note 65627 added to function.shell-exec
| From: | squeegee at osu1 dot php dot net | Date: | Thu, 04 May 2006 17:36:44 +0000 |
| Subject: | note 65627 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110558@lists.php.net to get a copy of this message | ||
Each time you call shell_exec, it operates in a completely new shell. So if you need to do different
multiple things in it based on whatever criteria, assemble your command ahead of time:
instead of
<?php
shell_exec("cd $path_to_dir");
shell_exec("ls -l");
?>
which, as you noted, won't work, do
<?php
$cmd = "cd $path_to_dir; ";
if($a == true)$cmd .= "ls -l";
else $cmd .= "du -h";
$result = shell_exec($cmd);
?>
----
Server IP: 64.71.164.2
Probable Submitter: 66.188.26.156
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.shell-exec.php
Edit -- http://master.php.net/note/edit/65627
Del: integrated -- http://master.php.net/note/delete/65627/integrated
Del: useless -- http://master.php.net/note/delete/65627/useless
Del: bad code -- http://master.php.net/note/delete/65627/bad+code
Del: spam -- http://master.php.net/note/delete/65627/spam
Del: non-english -- http://master.php.net/note/delete/65627/non-english
Del: in docs -- http://master.php.net/note/delete/65627/in+docs
Del: other reasons-- http://master.php.net/note/delete/65627
Reject -- http://master.php.net/note/reject/65627
Search -- http://master.php.net/manage/user-notes.php