note 88052 added to function.shell-exec
| From: | Rgemini at osu1 dot php dot net | Date: | Wed, 07 Jan 2009 23:46:22 +0000 |
| Subject: | note 88052 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148930@lists.php.net to get a copy of this message | ||
A simple way to handle the problem of capturing stderr output when using shell-exec under windows is
to call ob_start() before the command and ob_end_clean() afterwards, like this:
<?php
ob_start()
$dir = shell_exec('dir B:');
if is_null($dir)
{ // B: does not exist
// do whatever you want with the stderr output here
}
else
{ // B: exists and $dir holds the directory listing
// do whatever you want with it here
}
ob_end_clean(); // get rid of the evidence :-)
?>
If B: does not exist then $dir will be Null and the output buffer will have captured the message:
'The system cannot find the path specified'.
(under WinXP, at least). If B: exists then $dir will contain the directory listing and we probably
don't care about the output buffer. In any case it needs to be deleted before proceeding.
----
Server IP: 92.48.74.199
Probable Submitter: 81.86.122.70
----
Manual Page -- http://www.php.net/manual/en/function.shell-exec.php
Edit -- https://master.php.net/note/edit/88052
Del: integrated -- https://master.php.net/note/delete/88052/integrated
Del: useless -- https://master.php.net/note/delete/88052/useless
Del: bad code -- https://master.php.net/note/delete/88052/bad+code
Del: spam -- https://master.php.net/note/delete/88052/spam
Del: non-english -- https://master.php.net/note/delete/88052/non-english
Del: in docs -- https://master.php.net/note/delete/88052/in+docs
Del: other reasons-- https://master.php.net/note/delete/88052
Reject -- https://master.php.net/note/reject/88052
Search -- https://master.php.net/manage/user-notes.php