Net_SSH2的输出被切断了吗?

时间:2019-07-19 22:20:25

标签: php linux ssh phpseclib

我正在使用phpseclib(Net_SSH2)在PHP中运行命令。问题在于输出似乎在较长的行上被切断。这是一个问题,因为我正在使用PHP从每一行中查找某些详细信息(并且现在大部分这些详细信息都已被删除)。

这是我当前的代码:

set_include_path(__DIR__ . '/phpseclib');
include("Net/SSH2.php");

$ssh = new Net_SSH2('example.com', 22);
if (!$ssh->login('testing', "123456")) exit('Login Failed');

$shell = $ssh->exec('ps aux');
echo $shell;

这应该是回声:

267745  4370  0.0  0.1 7148 2220  -  SNJ  21:56   0:00.02 sh /home/public/crons/syncing.sh
267745 86056  0.0  0.0 4240 1600  -  SNCJ 22:15   0:00.00 sleep 10
267745 37349  0.0  0.1 7864 3512 14  SNsJ 16:36   0:01.14 -bash (bash)
267745 86089  0.0  0.1 6992 2228 14  RN+J 22:15   0:00.00 ps aux

这就是回声:

267745  4370  0.0  0.1  7148 2220  -  SNJ  21:56   0:00.02 sh /home/public/cron
267745 86056  0.0  0.0  4240 1600  -  SNCJ 22:15   0:00.00 sleep 10
267745 37349  0.0  0.1  7864 3512 14  SNsJ 16:36   0:01.14 -bash (bash)
267745 86099  0.0  0.1  6992 2228  -  RNsJ 22:15   0:00.88 ps aux

这是上面示例中有问题的行:

267745  4370  0.0  0.1 7148 2220  -  SNJ  21:56   0:00.02 sh /home/public/crons/syncing.sh

什么会导致这种情况发生?

我当前正在使用phpseclib 1.0.11。

1 个答案:

答案 0 :(得分:0)

引用https://github.com/phpseclib/phpseclib/issues/1385

  

似乎像$ssh->setWindowColumns(...)可能会做您想要的。默认情况下,窗口栏为80,除非您自行设置。