Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

Rgemini
16 years ago
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.

<< Back to user notes page

To Top