0

我正在使用 php ssh2_exec 在远程 Linux 服务器上执行 ps aux 命令...启动连接的服务器是 Ubuntu 14.04,而我正在与之通信的服务器是 Centos 6.6。

两个系统都是完全更新的,我在 Ubuntu 系统上使用以下版本的 PHP 和 Apache:

apache2 2.4.7-1ubuntu4.5 libapache2-mod-php5 5.5.9+dfsg-1ubuntu4.11

php5 5.5.9+dfsg-1ubuntu4.11

我正在使用以下代码发送命令并捕获流:

echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
           flush();
           echo $line."<br />";
       }
echo '</pre>';
echo '<br />';
unset($connection);

$command 定义为: $command = "ps aux |sed '/[.*]/d'";

该命令运行,但返回的文本在显示远程系统上运行的进程的同时,被文本击中......下面是一个链接,指向正在发生的事情的图像。

https://www.joeman1.com/images/stikethoughtest.png

(我会张贴图片,但我是新来的,需要一些声誉;))。

当我在命令行上使用 php -f 时不会发生这种情况,只是在浏览器中 - IE、Firefox 和 Chrome 已经过测试。

关于如何解决这个问题的任何想法?如果您需要更多信息,请告诉我。

谢谢!乔

4

1 回答 1

0

尝试检查您的 HTML 源代码。或者:

<?php
echo '<pre>';
$stream = ssh2_exec($connection, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
while($line = fgets($stream_out)) {
           flush();
           // convert the string to HTML Entities
           // Since you're getting data from a stream, no telling what might come out.
           echo htmlentities($line)."<br />";
       }
echo '</pre>';
echo '<br />';
unset($connection);
?>
于 2015-08-12T23:09:10.623 回答