note 101579 added to function.exec
| From: | alvaro at demogracia dot com | Date: | Mon, 27 Dec 2010 13:27:01 +0000 |
| Subject: | note 101579 added to function.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175234@lists.php.net to get a copy of this message | ||
In Windows, exec() issues an internal call to "cmd /c your_command". This implies that
your command must follow the rules imposed by cmd.exe which includes an extra set of quotes around
the full command:
- http://ss64.com/nt/cmd.html
Current PHP versions take this into account and add the quotes automatically, but old versions
didn't.
Apparently, the change was made in PHP/5.3.0 yet not backported to 5.2.x because it's a
backwards incompatible change. To sum up:
- In PHP/5.2 and older you have to surround the full command plus arguments in double quotes
- In PHP/5.3 and greater you don't have to (if you do, your script will break)
If you are interested in the internals, this is the source code:
sprintf(cmd, "%s /c \"%s\"", TWG(comspec), command);
It can be found at http://svn.php.net/viewvc/ (please find
php/php-src/trunk/TSRM/tsrm_win32.c, the comment system doesn't allow the direct link).
----
Server IP: 80.64.47.13
Probable Submitter: 80.37.14.51
----
Manual Page -- http://www.php.net/manual/en/function.exec.php
Edit -- https://master.php.net/note/edit/101579
Del: integrated -- https://master.php.net/note/delete/101579/integrated
Del: useless -- https://master.php.net/note/delete/101579/useless
Del: bad code -- https://master.php.net/note/delete/101579/bad+code
Del: spam -- https://master.php.net/note/delete/101579/spam
Del: non-english -- https://master.php.net/note/delete/101579/non-english
Del: in docs -- https://master.php.net/note/delete/101579/in+docs
Del: other reasons-- https://master.php.net/note/delete/101579
Reject -- https://master.php.net/note/reject/101579
Search -- https://master.php.net/manage/user-notes.php