note 107325 deleted from function.ssh2-exec by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 21:26:28 +0000 |
| Subject: | note 107325 deleted from function.ssh2-exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187889@lists.php.net to get a copy of this message | ||
Note Submitter: cuisdy at gmail dot com
----
@christopher dot millward
This worked for me, to get both stdout and stderr:
<?php
// $ssh2 is a resource returned by ssh2_connect()
// $cmd is any command you want to exec remotely
$stdio = ssh2_exec($ssh2, $cmd);
stream_set_blocking($stdio, true);
$stdout = stream_get_contents($stdio);
$stderr = stream_get_contents(ssh2_fetch_stream($stdio, SSH2_STREAM_STDERR));