note 21866 added to function.shell-exec
| From: | mark at catalyst dot net dot nz | Date: | Wed, 29 May 2002 21:08:36 +0000 |
| Subject: | note 21866 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31168@lists.php.net to get a copy of this message | ||
if u feel the need to escape the shell command before running it through shell_exec, don't.
it will not work.
In the below example, i want the word count from a word document.
e.g.
$cmd = "/usr/bin/extract++ -v3 -s $path/stopwords.tmp -e doc $AL | wc -w $AL.txt";
$temp = escapeshellcmd($cmd);
$return_string = shell_exec($temp);
would try and execute "/usr/bin/extract++ -v3 -s $path/stopwords.tmp -e doc $AL \| wc -w
$AL.txt" in the cmd shell.
this doesn't work (as it seems to want to include th escape characters as part of the command
to execute).
by not doing the $temp = escapeshellcmd($cmd);...
i.e. $cmd = "/usr/bin/extract++ -v3 -s $path/stopwords.tmp -e doc $AL | wc -w $AL.txt";
$return_string = shell_exec($cmd);
works as there are no escape characters in the resulting command.
--
http://www.php.net/manual/en/function.shell-exec.php
http://master.php.net/manage/user-notes.php?action=edit+21866
http://master.php.net/manage/user-notes.php?action=delete+21866
http://master.php.net/manage/user-notes.php?action=reject+21866