我正在使用 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.11php5 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 进行了测试。
关于如何解决这个问题有什么想法吗?如果您需要更多信息,请告诉我。
谢谢! 乔
最佳答案
尝试检查您的 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);
?>
关于php - php 流输出上的删除线字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31947516/