note 65627 deleted from function.shell-exec by cmb
| From: | cmb@php.net | Date: | Sun, 14 Jul 2019 11:34:21 +0000 |
| Subject: | note 65627 deleted from function.shell-exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211589@lists.php.net to get a copy of this message | ||
Note Submitter: squeegee
----
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);
?>