From dc76cf5b8e679f666f58ece6de0caeb246c416cf Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 28 May 2013 17:02:27 -0500 Subject: [PATCH] SSH2: add $callable parameter to exec() --- phpseclib/Net/SSH2.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 2a79265f..bd676dc3 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2013,7 +2013,7 @@ class Net_SSH2 { * @return String * @access public */ - function exec($command, $block = true) + function exec($command, $callback = NULL) { $this->curTimeout = $this->timeout; $this->stdErrorLog = ''; @@ -2097,7 +2097,7 @@ class Net_SSH2 { $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; } @@ -2106,11 +2106,15 @@ class Net_SSH2 { $temp = $this->_get_channel_packet(NET_SSH2_CHANNEL_EXEC); switch (true) { case $temp === true: - return $output; + return is_callable($callback) ? true : $output; case $temp === false: return false; default: - $output.= $temp; + if (is_callable($callback)) { + $callback($temp); + } else { + $output.= $temp; + } } } }