-
Notifications
You must be signed in to change notification settings - Fork 1.7k
problem passing arguments with spaces to a process running under cmd.exe #2835
Copy link
Copy link
Closed
Labels
Description
With the Fall Creators Update I can't figure out a way to pass arguments with spaces to a process running under cmd.exe. Consider the following program compiled to args.exe:
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
printf("\nCommand-line arguments:\n");
for (i = 0; i < argc; i++)
{
printf(" argv[%d] %s\n", i, argv[i]);
}
}
Here is the output from a Windows shell:
C:\Users\Dan>cmd /c "z:\bin\args.exe "foo bar""
Command-line arguments:
argv[0] z:\bin\args.exe
argv[1] foo bar
C:\Users\Dan>cmd /c "z:\bin\args.exe \"foo bar\""
Command-line arguments:
argv[0] z:\bin\args.exe
argv[1] "foo
argv[2] bar"
Note that the inner quotes cause foo and bar to be treated as a single argument unless you escape those quotes. Here is from a WSL session:
root@DESKTOP-MVKOR9S:~# cmd.exe /c "z:\bin\args.exe "foo bar""
Command-line arguments:
argv[0] z:\bin\args.exe
argv[1] foo
argv[2] bar
root@DESKTOP-MVKOR9S:~# cmd.exe /c "z:\bin\args.exe \"foo bar\""
Command-line arguments:
argv[0] z:\bin\args.exe
argv[1] "foo
argv[2] bar"
Here foo and bar are treated as separate arguments whether you use quotes or not.
Reactions are currently unavailable