Monthly Archives: December 2019

PowerShell may spoil command-line arguments when running external programs

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 are no problems with CMD. After researching, we found that PowerShell may modify command line parameters.

I wrote a simple program which displays its own command-line string:

int main(int argc, char *argv[], char *envp[]) {

	_tprintf(_T("\nCommand line: %s\n"), GetCommandLine());

}

Let’s run this program in Command Prompt and  PowerShell with the following arguments:

param1 “param2” ‘param3’ “param 4” ‘param 5’ “param/6” ‘param/7’

As you can see, the output of this program exactly matches the input.

Surprise! PowerShell changes command line by removing the quotation marks when an argument has no space and replacing single quotes with the double quotes. And this may affect third-party utilities.

Why does PowerShell do that?

PowerShell is not just a console to run programs. It is a system to run scripts. And it considers strings enclosed in quotes as PowerShell strings.

Workaround

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.

As a workaround, you can enclose double quotes inside single quotes or use two sequential double quotes:

All seems to be OK except ‘param 5’ parameter, but I believe It’s more important that param/6 and param/7 problems were fixed since they could conflict with command-line switches.

Facebooktwitterredditpinterestlinkedinmail