我一直在尝试格式化SSH2-> read()方法的输出。我尝试使用ANSI.php如下 http://phpseclib.sourceforge.net/ssh/examples.html#top
我的代码
<?php
include('Net/SSH2.php');
include('File/ANSI.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
$ansi = new File_ANSI();
$ssh->enablePTY();
$ssh->exec("powershell.exe\n");
$ssh->setTimeout(2);
echo $ssh->read();
$ssh->write("ls\n");
echo $ssh->read();
?>
输出中包含ANSI字符,没有&#39; ls&#39;结果
(B)0[?7l[H[J[1;1HWindows PowerShell[2;1HCopyright (C) 2013 Microsoft Corporation. All rights reserved.[4;1HPS C:\Users\Administrator> (B)0[?7l[H[J[1;1H [2;1H [3;1H [4;1H [5;1H [6;1H [7;1H [8;1H [9;1H [10;1H [11;1H [12;1H [13;1H [14;1H [15;1H [16;1H [17;1H [18;1H [19;1H [20;1H [21;1H [22;1H [23;1H [24;1H [1;1HMicrosoft Windows [Version 6.3.9600][2;1H(c) 2013 Microsoft Corporation. All rights reserved.[4;1HC:\Users\Administrator>ls[5;1H
我需要这样的东西,它甚至不接近:
我该如何格式化?
答案 0 :(得分:0)
仅仅因为你正在初始化课程并不意味着你要包括它大声笑。试试这个:
<?php
include('Net/SSH2.php');
include('File/ANSI.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
$ansi = new File_ANSI();
$ssh->enablePTY();
$ssh->exec("powershell.exe\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
$ssh->write("ls\n");
$ansi->appendString($ssh->read());
echo $ansi->getScreen();
?>
即。将所有$ssh->read()
来电包裹在$ansi->appendString()
中,然后$ansi->getScreen()
。或者可能只在$ssh->read()
之后$ssh->write("ls\n")
包裹$ansi->appendString()
。你也可以做$ansi->getHistory()
。