0

我正在使用以下代码与 SSH 会话进行交互。一切都很好,直到最后一行代码。

我的网页上的屏幕打印效果很好,直到最后一个 getScreen() 抛出以下错误。我会说,在我的最后一个命令之后,ssh 会话窗口(至少在 putty 中)进入了一种实时模式,几乎就像一个尾命令,并且窗口将在进入 ssh 会话时填充信息。它看起来是预先确定的尺寸?

理想情况下,我想将进入这个窗口的内容通过管道传输到一个文件中,这是我的最终目标,但现在只是让它显示在屏幕上会很有帮助。

PHP Notice:  Undefined offset: 79 in E:\jackwad\IIS\portal\File\ANSI.php on line 556
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 499
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 500
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 501
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 507
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 508
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 509
PHP Notice:  Trying to get property 'bold' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 515
PHP Notice:  Trying to get property 'underline' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 522
PHP Notice:  Trying to get property 'blink' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 529
PHP Notice:  Undefined offset: 79 in E:\jackwad\IIS\portal\File\ANSI.php on line 558
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 499
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 503
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 507
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 511
PHP Notice:  Trying to get property 'bold' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 515
PHP Notice:  Trying to get property 'underline' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 522
PHP Notice:  Trying to get property 'blink' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 529

我的代码:

include('Net/SSH2.php');
include('File/ANSI.php');

$ssh = new Net_SSH2('1xx.xx.xx.xx');
if (!$ssh->login('xxxxx', 'xxxxxxxx')) {
    exit('Login Failed');
}

$ansi = new File_ANSI();

$ansi->appendString($ssh->read('username@username:~$'));
$ssh->write("\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("sat\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("W2KTT\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("some text 102\n");
$ssh->setTimeout(5);
$ansi->appendString($ssh->read());
$ansi->getScreen(); //this is the problem line

ANSI.php

500 - function _getScreen()
501 - {
502 -     $output = '';
503 -     $last_attr = $this->base_attr_cell;
504 -     for ($i = 0; $i <= $this->max_y; $i++) {
505 -         for ($j = 0; $j <= $this->max_x; $j++) {
506 -             $cur_attr = $this->attrs[$i][$j];
507 -             $output.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->screen[$i][$j]) ? $this->screen[$i][$j] : '');
508 -             $last_attr = $this->attrs[$i][$j];
509 -         }
510 -         $output.= "\r\n";
511 -     }
512 -     $output = substr($output, 0, -2);
513 -     // close any remaining open tags
514 -     $output.= $this->_processCoordinate($last_attr, $this->base_attr_cell, '');
515 -     return rtrim($output);
516 - }
4

0 回答 0