dongqiongjiong4740 2015-08-11 16:46 采纳率: 0%
浏览 58
已采纳

php流输出上的删除字符

I am using php ssh2_exec to execute a ps aux command on a remote Linux server... The server initiating the connection is Ubuntu 14.04 and the server I am communicating with is Centos 6.6.

Both systems are fully updates and I am using the following versions of PHP and Apache on the Ubuntu system:

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

php5 5.5.9+dfsg-1ubuntu4.11

I am using the following code to send the command and capture the stream:

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 is defined as: $command = "ps aux |sed '/[.*]/d'";

The command runs, but the returned text, while showing the processes running on the remote system, is stricken through text... Below is a link to an image of what is happening.

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

(I would have posted the image, but Im new around here and need some reputation ;)).

This does not happen when I use php -f on the command line, just in a browser - IE, Firefox, and Chrome was tested.

Any ideas on how to resolve this? If you need more information, please let me know.

Thanks! Joe

  • 写回答

1条回答 默认 最新

  • dsgwdigu84950 2015-08-12 23:09
    关注

    Try checking your HTML Source. Or:

    <?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);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探