|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-09-02 11:07 UTC] sam at freepeers dot com
Description: ------------ Running PHP on Windows 2000 with IIS 5. Basic program executation does not work in certain cases. This is ok: $output = `C:\executable.exe C:\\file1.txt`; Now, lets suppose that both the filename and the executable names contain spaces, and therefore each are to be enclosed in quotes. Then it fails: This is not ok: $output = `"C:\executable.exe" "C:\\file1.txt"`; This is ok again: $output = `C:\executable.exe "C:\\file1.txt"`; This is also ok: $output = `"C:\executable.exe" C:\\file1.txt`; So, the problem arises when BOTH the command and the file are enclosed in quotes. In some cases you do need to enclose both the command and the file in quotes. You will not be able to. This affects all forms of command execution (exec, system, backticks...) Reproduce code: --------------- 1. Create file called "Test.txt" and put it into C: drive. Put some random text in it. 2. Try this code: <?php $output = ""; $output = `more C:\\Test.txt`; echo "Test.txt contains $output. This works<br><br>"; $output = ""; $output = `"more" C:\\Test.txt`; echo "Test.txt contains $output. This works<br><br>"; $output = ""; $output = `more "C:\\Test.txt"`; echo "Test.txt contains $output. This works<br><br>"; $output = ""; $output = `"more" "C:\\Test.txt"`; echo "Test.txt contains $output. This does not works<br><br>"; ?> Expected result: ---------------- Test.txt contains Contents of file. . This works Test.txt contains Contents of file. . This works Test.txt contains Contents of file. . This works Test.txt contains Contents of file. . This does not works Actual result: -------------- Test.txt contains Contents of file. . This works Test.txt contains Contents of file. . This works Test.txt contains Contents of file. . This works Test.txt contains . This does not works PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 21:00:01 2025 UTC |
Index: proc_open.c =================================================================== RCS file: /repository/php-src/ext/standard/proc_open.c,v retrieving revision 1.57 diff -u -r1.57 proc_open.c --- proc_open.c 28 May 2007 23:00:25 -0000 1.57 +++ proc_open.c 2 Aug 2007 09:30:57 -0000 @@ -740,7 +740,7 @@ if (bypass_shell) { newprocok = CreateProcess(NULL, command, &security, &security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi); } else { - spprintf(&command_with_cmd, 0, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); + spprintf(&command_with_cmd, 0, "%s /c \"%s\"", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW, env.envp, cwd, &si, &pi);From the cmd.exe /? help If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 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. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. My intent is to force the command line supplied by exec() et. al. to be wrapped in a pair of quotes, thus forcing option 2 to be used. For older windows (9x), using command.com, the help is ... /C string Carries out the command specified by string, and then stops. If 9x is not a concern (I'm getting it tested next week as I don't have a 9x machine at hand), then the first patch could be used which only wraps "" around NT+.