note 99089 added to function.ssh2-exec
| From: | christopher dot millward at gmail dot com | Date: | Tue, 27 Jul 2010 06:15:19 +0000 |
| Subject: | note 99089 added to function.ssh2-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171159@lists.php.net to get a copy of this message | ||
There doesn't appear to be a way to get data from BOTH stderr and stdout streams
simultaneously, or at least I've yet to find one.
The following code *should* get the error message written to stderr, but if the call to
stream_get_contents() for stdout is run first, the subsequent call for stderr won't return
anything.
If the order of the statements is reversed, the call for stderr will return any errors and call for
stdout will return nothing
<?php
// Run a command that will probably write to stderr (unless you have a folder named /hom)
$stream = ssh2_exec($connection, "cd /hom");
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
// Enable blocking for both streams
stream_set_blocking($errorStream, true);
stream_set_blocking($stream, true);
// Whichever of the two below commands is listed first will receive its appropriate output. The
second command receives nothing
echo "Output: " . stream_get_contents($stream);
echo "Error: " . stream_get_contents($errorStream);
// Close the streams
fclose($errorStream);
fclose($stream);
?>
My initial suspicion is that either a) I've done something wrong or b) the blocking nature of
both streams means that by the time first stream has received data and returned, the buffer for the
second stream has already emptied.
I've done preliminary tests with blocking disabled, but haven't had any luck there either.
----
Server IP: 69.147.83.197
Probable Submitter: 99.234.102.60
----
Manual Page -- http://www.php.net/manual/en/function.ssh2-exec.php
Edit -- https://master.php.net/note/edit/99089
Del: integrated -- https://master.php.net/note/delete/99089/integrated
Del: useless -- https://master.php.net/note/delete/99089/useless
Del: bad code -- https://master.php.net/note/delete/99089/bad+code
Del: spam -- https://master.php.net/note/delete/99089/spam
Del: non-english -- https://master.php.net/note/delete/99089/non-english
Del: in docs -- https://master.php.net/note/delete/99089/in+docs
Del: other reasons-- https://master.php.net/note/delete/99089
Reject -- https://master.php.net/note/reject/99089
Search -- https://master.php.net/manage/user-notes.php