in reply to Re^4: true from (-e "") on Windoze (" is an illegal filename character
in thread true from (-e "") on Windoze
You are mixing command line parsing in command.com / cmd.exe and the Windows-APIs.
Unlike in Unix, command line parsing is the job of the invoked program (and not that of the shell) on Windows, this typically happens in the C RTL. The command interpreters themself also parse their input, but only to find the executable or build-in command and to handle redirections. The build-in commands (dir, cd, ...) must also parse their argument string, probably using the same or very similar routines.
After that parsing has happened, quotes and escape characters are gone, and the program or build-in command has a list of (unescaped) arguments, some of them are passed to API functions. The API functions do not remove quotes:
X:\>dir 979536.exe Volume in drive X is RAMDISK Volume Serial Number is 065B-0000 Directory of X:\ 05.07.2012 22:04 121.535 979536.exe 1 File(s) 121.535 bytes 0 Dir(s) 129.867.776 bytes free X:\>dir "979536.exe" Volume in drive X is RAMDISK Volume Serial Number is 065B-0000 Directory of X:\ 05.07.2012 22:04 121.535 979536.exe 1 File(s) 121.535 bytes 0 Dir(s) 129.867.776 bytes free X:\>perl -Mautodie -e "open $f,'979536.exe'" X:\>perl -Mautodie -e "open $f,chr(34).'979536.exe'.chr(34)" Can't open($fh, '"979536.exe"'): Invalid argument at -e line 1 X:\>type openfail.c #include <stdio.h> #include <errno.h> int main(int argc, char ** argv) { FILE * f; if ((f=fopen("979536.exe","r"))==NULL) { perror("open without quotes"); } else { fclose(f); } if ((f=fopen("\"979536.exe\"","r"))==NULL) { perror("open with quotes"); } else { fclose(f); } return 0; } X:\>gcc -Wall -pedantic -o openfail.exe openfail.c X:\>.\openfail.exe open with quotes: Invalid argument X:\>
Alexander
|
|---|