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 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率