{"id":427,"date":"2019-12-22T17:51:29","date_gmt":"2019-12-22T17:51:29","guid":{"rendered":"http:\/\/eventlogxp.com\/blog\/?p=427"},"modified":"2019-12-22T17:51:30","modified_gmt":"2019-12-22T17:51:30","slug":"powershell-may-spoil-command-line-arguments-when-running-external-programs","status":"publish","type":"post","link":"https:\/\/eventlogxp.com\/blog\/powershell-may-spoil-command-line-arguments-when-running-external-programs\/","title":{"rendered":"PowerShell may spoil command-line arguments when running external programs"},"content":{"rendered":"\n<p>Nowadays, Windows PowerShell is considered as a replacement of the classic Windows Console (Command Prompt) utility. In Windows 10, it can be set as a default console in Win+X menu<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" width=\"473\" height=\"86\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershellsetting.png\" alt=\"\" class=\"wp-image-428\" srcset=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershellsetting.png 473w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershellsetting-300x55.png 300w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/figure><\/div>\n\n\n\n<p>In most cases, when you run command-line utilities from PowerShell and Command Prompt, they will behave exactly the same. However, we discovered that sometimes our command-line utilities work incorrectly when starting from PowerShell, while there are no problems with CMD. After researching, we found that PowerShell may modify command line parameters.<\/p>\n\n\n\n<p>I wrote a simple program which displays its own command-line string:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int main(int argc, char *argv[], char *envp[]) {\n\n\t_tprintf(_T(\"\\nCommand line: %s\\n\"), GetCommandLine());\n\n}<\/code><\/pre>\n\n\n\n<p>Let&#8217;s run\nthis program in Command Prompt and &nbsp;PowerShell\nwith the following arguments:<\/p>\n\n\n\n<p>param1\n&#8220;param2&#8221; &#8216;param3&#8217; &#8220;param 4&#8221; &#8216;param 5&#8217; &#8220;param\/6&#8221;\n&#8216;param\/7&#8217;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok.png\" data-rel=\"lightbox-gallery-at4t8bZH\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" width=\"790\" height=\"410\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok.png\" alt=\"\" class=\"wp-image-429\" srcset=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok.png 790w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok-300x156.png 300w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok-768x399.png 768w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/command_prompt_ok-660x343.png 660w\" sizes=\"(max-width: 790px) 100vw, 790px\" \/><\/a><\/figure>\n\n\n\n<p>As you can see, the output of this program exactly matches the input.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue.png\" data-rel=\"lightbox-gallery-at4t8bZH\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" width=\"790\" height=\"411\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue.png\" alt=\"\" class=\"wp-image-431\" srcset=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue.png 790w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue-300x156.png 300w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue-768x400.png 768w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_issue-660x343.png 660w\" sizes=\"(max-width: 790px) 100vw, 790px\" \/><\/a><\/figure>\n\n\n\n<p>Surprise! PowerShell\nchanges command line by removing the quotation marks when an argument has no\nspace and replacing single quotes with the double quotes. And this may affect\nthird-party utilities.<\/p>\n\n\n\n<p>Why does\nPowerShell do that?<\/p>\n\n\n\n<p>PowerShell\nis not just a console to run programs. It is a system to run scripts. And it\nconsiders strings enclosed in quotes as PowerShell strings. <\/p>\n\n\n\n<h4>Workaround<\/h4>\n\n\n\n<p>First, if you come across such an issue, we recommend you contact the developers and report this issue. In our products, we will fix these incompatibility issues soon.<\/p>\n\n\n\n<p>As a\nworkaround, you can enclose double quotes inside single quotes or use two\nsequential double quotes:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok.png\" data-rel=\"lightbox-gallery-at4t8bZH\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" width=\"790\" height=\"411\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok.png\" alt=\"\" class=\"wp-image-432\" srcset=\"https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok.png 790w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok-300x156.png 300w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok-768x400.png 768w, https:\/\/eventlogxp.com\/blog\/wp-content\/uploads\/2019\/12\/powershell_ok-660x343.png 660w\" sizes=\"(max-width: 790px) 100vw, 790px\" \/><\/a><\/figure>\n\n\n\n<p>All seems to be OK except &#8216;param 5&#8217; parameter, but I believe It&#8217;s more important that param\/6 and param\/7 problems were fixed since they could conflict with command-line switches.<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;t=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F12%2Fpowershell_issuse_featured.png&#038;p&#091;title&#093;=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;text=Check%20this%20Event%20Log%20Explorer%20blog%20post\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-reddit nolightbox\" data-provider=\"reddit\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Reddit\" href=\"https:\/\/www.reddit.com\/submit?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;title=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"reddit\" title=\"Share on Reddit\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/reddit.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-pinterest nolightbox\" data-provider=\"pinterest\" target=\"_blank\" rel=\"nofollow\" title=\"Pin it with Pinterest\" href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;media=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F12%2Fpowershell_issuse_featured.png&#038;description=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"pinterest\" title=\"Pin it with Pinterest\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/pinterest.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427&#038;title=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=PowerShell%20may%20spoil%20command-line%20arguments%20when%20running%20external%20programs&#038;body=Check%20this%20Event%20Log%20Explorer%20blog%20post:%20https%3A%2F%2Feventlogxp.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F427\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none\" src=\"https:\/\/eventlogxp.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>Nowadays, Windows PowerShell is considered as a replacement of the classic Windows Console (Command Prompt) utility. In Windows 10, it can be set as a default console in Win+X menu In most cases, when you run command-line utilities from PowerShell and Command Prompt, they will behave exactly the same. However, we discovered that sometimes our command-line utilities work incorrectly when starting from PowerShell, while there\u2026 <span class=\"read-more\"><a href=\"https:\/\/eventlogxp.com\/blog\/powershell-may-spoil-command-line-arguments-when-running-external-programs\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":435,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[55],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/427"}],"collection":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":3,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":436,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions\/436"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/media\/435"}],"wp:attachment":[{"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eventlogxp.com\/blog\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}