Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling cmd.exe from bash results in special escaping/transformation of input arguments #3724

Closed
andrewluotechnologies opened this issue Dec 22, 2018 · 2 comments
Labels

Comments

@andrewluotechnologies
Copy link

andrewluotechnologies commented Dec 22, 2018

I'm attempting to run this Win32 command through bash:

cmd.exe /c for %A in ("C:\Documents and Settings") do @echo %~sA

The correctly escaped command for bash is:

cmd.exe /c for %A in '("C:\Documents and Settings")' do @echo %~sA

However, this results in this error:

"("C:\Documents was unexpected at this time.

Using this command from bash:

cmd.exe /c echo for %A in '("C:\Documents and Settings")' do @echo %~sA

I can see that the command was transformed into:

for %A in "("C:\Documents and Settings")" do @echo %~sA

The "(\" should be just (" and the \")" should be )"

However, this appears to be special escaping for cmd.exe. If I run another executable, in this case a C++ executable that just prints out the arguments, I get the correct arguments:

test.exe /c for %A in '("C:\Documents and Settings")' do @echo %~sA

C:\Users\Andrew\source\repos\test\x64\Release\test.exe
/c
for
%A
in
("C:\Documents and Settings")
do
@echo
%~sA

The source for test.exe is below:

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
	for (int n(0); n < argc; ++n)
	{
		::std::cout << argv[n] << ::std::endl;
	}
	return 0;
}

Details of my environment:
uname -a:

Linux DESKTOP 4.4.0-17763-Microsoft #194-Microsoft Mon Dec 03 17:58:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux

ver:

Microsoft Windows [Version 10.0.17763.195]

@andrewluotechnologies
Copy link
Author

I confirmed that this still occurs in a recent insider build:
uname -a:
Linux DESKTOP-HLO5ULF 4.4.0-18917-Microsoft #1000-Microsoft Fri Jun 07 19:42:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux

ver:
Microsoft Windows [Version 10.0.18917.1000]

Also tested in WSL2 with same results.
uname -a for WSL2:
Linux DESKTOP-HLO5ULF 4.19.43-microsoft-standard #1 SMP Mon May 20 19:35:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants