SSH2: add $callable parameter to exec()

This commit is contained in:
terrafrost 2013-05-28 17:02:27 -05:00
parent f596c577cf
commit dc76cf5b8e

View File

@ -2013,7 +2013,7 @@ class Net_SSH2 {
* @return String * @return String
* @access public * @access public
*/ */
function exec($command, $block = true) function exec($command, $callback = NULL)
{ {
$this->curTimeout = $this->timeout; $this->curTimeout = $this->timeout;
$this->stdErrorLog = ''; $this->stdErrorLog = '';
@ -2097,7 +2097,7 @@ class Net_SSH2 {
$this->channel_status[NET_SSH2_CHANNEL_EXEC] = NET_SSH2_MSG_CHANNEL_DATA; $this->channel_status[NET_SSH2_CHANNEL_EXEC] = NET_SSH2_MSG_CHANNEL_DATA;
if (!$block || $this->in_request_pty_exec) { if ($callback === false || $this->in_request_pty_exec) {
return true; return true;
} }
@ -2106,14 +2106,18 @@ class Net_SSH2 {
$temp = $this->_get_channel_packet(NET_SSH2_CHANNEL_EXEC); $temp = $this->_get_channel_packet(NET_SSH2_CHANNEL_EXEC);
switch (true) { switch (true) {
case $temp === true: case $temp === true:
return $output; return is_callable($callback) ? true : $output;
case $temp === false: case $temp === false:
return false; return false;
default: default:
if (is_callable($callback)) {
$callback($temp);
} else {
$output.= $temp; $output.= $temp;
} }
} }
} }
}
/** /**
* Creates an interactive shell * Creates an interactive shell