|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57140 ssh2_exec bug
Submitted: 2006-07-13 04:42 UTC Modified: 2006-07-13 10:32 UTC
From: robert dot reichel at zg dot t-com dot hr Assigned:
Status: Not a bug Package: ssh2 (PECL)
PHP Version: 5.1.0 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: robert dot reichel at zg dot t-com dot hr
New email:
PHP Version: OS:


 [2006-07-13 04:42 UTC] robert dot reichel at zg dot t-com dot hr
When I execute command on remote server with 'ssh2_exec' function and executed command is valid, I receive expected result. For example if I execute command 'dir', I receive stream with all directory entries.

But if I execute an invalid command, for example 'dirr', I receive empty stream. When I execute same command using my SSH client (I use PuTTY), I receive the following message: '-bash: dirr: command not found'

I also tried to use callback functions but without success.

Reproduce code:
$Hostname = 'myhost';
$Username = 'myuser';
$Password = 'mypass';
$Output = null;
$Methods = array();
$Callbacks = array ('ignore'=>'cbIgnore', 'debug'=>'cbDebug', 'macerror'=>'cbMACError', 'disconnect'=>'cbDisconnect');

//connecting remote server...
if (false === $Connection = ssh2_connect($Hostname, 22, $Methods, $Callbacks)) {
  die ("Unable to connect '$Hostname'.\n");
} else {
  echo "Done.\n";
//authenticating user...
if (false === ssh2_auth_password($Connection, $Username, $Password)) {
  die ("Unable to authenticate user.\n");
//executing command on remote server
if (false === $Stream = ssh2_exec($Connection, 'di')) {
  die ("Unable to execute command on remote server.\n");
//set blocking mode on a stream
stream_set_blocking($Stream, true);

//set output string
while ($Block = fread($Stream, 8192)) {
  $Output.= $Block;
fclose ($Stream);
echo $Output;

function cbIgnore ($message)
  die ("IGNORE: $message");
function cbDebug ($message, $language, $always_display)
  die ("DEBUG: $message");
function cbMACError ($packet)
  echo ("MAC_ERROR: $packet");
  return true;
function cbDisconnect ($reason, $message, $language)
  die ("DISCONNECT: $message");


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-13 10:32 UTC]
That's because errors come back on the STDERR substream.  You can fetch this substream using:

$stdio = ssh2_exec($connection, "dirr");
$stderr = ssh2_fetch_stream($stdio, SSH2_STREAM_STDERR);
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 07:01:29 2024 UTC