WSL: Transferring quotes from bash to windows app doesn't work as expected

hello.c #include <stdio.h> int main (void) { printf (INIT_VER_STR); } user@machine:/mnt/d/code$ gcc -c hello.c -DINIT_VER_STR="\"Hello, world\"" -e output >> … int main (void) { printf ("Hello, world"); } << Note: gcc is Ubuntu app

user@machine:/mnt/d/code$ armcc.exe -c test.c -DINIT_VER_STR="\"Hello, world\"" -e output >> … int main (void) { printf (Hello,); }` << Note: armcc.exe is Windows app

Windows build number .15007 Note: running armcc.exe under cygwin yeilds expected results.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Upon further inspection it appears that Ben’s fix has broken this use case. Worse, I don’t see a way to circumvent the new bug. 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 /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 /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.

I have a fix for this issue and #2164 in code review currently.