note 21866 rejected from function.shell-exec by dams
| From: | dams@php.net | Date: | Wed, 29 May 2002 22:41:38 +0000 |
| Subject: | note 21866 rejected from function.shell-exec by dams | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-31173@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.