Page 1 of 1

How do I preserve quotes?

Posted: 27 Aug 2011 22:49
by taripo
How do I preserve quotes?

Here is a C program to test
http://pastebin.com/y4u7A4mw
#include <stdio.h>

int main(int argc, char *argv[]) {
int i = 0;
while (argv[i]) {
printf("argv[%d] = %s\n", i, argv[i]);
i++;
}
return 0;
}

I've compiled it, w_win.exe

All it does is show me each argument parsed.

W:\other>w_win.exe "c:\program files\internet explorer\iexplore.exe"
argv[0] = w_win.exe
argv[1] = c:\program files\internet explorer\iexplore.exe

W:\other>

Here's another example

C:\Program Files\Internet Explorer>copy iexplore.exe "i explore.exe"
1 file(s) copied.

C:\Program Files\Internet Explorer>path=%path%;w:\other

C:\Program Files\Internet Explorer>w_win "i explore.exe"
argv[0] = w_win
argv[1] = i explore.exe

C:\Program Files\Internet Explorer>

^^ Notice that quotes aren't preserved.

Even though I think it matches these conditions (cmd /?)
"
1. If all of the following conditions are met, then quote characters
on the command line are preserved:

- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
the two quote characters
- the string between the two quote characters is the name
of an executable file.
"

So, how can I get quotes to be preserved?

Furthermore, there is this which is strange..

The escape character in CMD.EXE is meant to be ^

but howcome here it acts like it's backslash?

W:\other>w_win "abc"
argv[0] = w_win
argv[1] = abc

W:\other>w_win ^"abc^"
argv[0] = w_win
argv[1] = abc

W:\other>w_win \"abc\"
argv[0] = w_win
argv[1] = "abc"

W:\other>