Working with "C: \ Program Files (x86)" I had a strange problem with a program located somewhere below this path. I reproduced the behavior using a test program.
int _tmain(int argc, _TCHAR* argv[])
{
wprintf(L"%d\n", argc);
for (int i = 0; i < argc; i++) {
wprintf(L"%s\n", argv[i]);
}
return 0;
}
The program counts and returns all command line arguments (including the path to the program used to identify the program). I called it "HelloWorld.exe" because I was in a hurry.
For the three possible ways to run the program, it gives two different results, while I expected the same result.
When I run HelloWorld.exe from my own directory, the output
1
HelloWorld.exe
This conclusion is correct and expected.
When I run HelloWorld.exe, which is located in "P: \ Test (x86)", from another place and uses the quoted path, the output
1
P:\Test (x86)\HelloWorld.exe
This conclusion is also correct and expected.
However, when I run HelloWorld.exe from another place and use the path with escaped spaces and brackets, the program is found (i.e. the path is correct), but the result is incorrect:
2
P:\Test
(x86)\HelloWorld.exe
For some reason shielded space in
P: \ Test \ ^ ^ (x86 ^) \ HelloWorld.exe
For some reasonit becomes an operator to read the space somehow, and Windows, after reading the path as a string alone , to find the program, decides that it is actually two lines, before creating this array the program then refers to.
This behavior occurs both in Windows XP (x86) and in Windows Server 2008 R2 (x64). I assume that it is present in all versions of Windows (NT).