在PHP中捕获ncurses shell输出 [英] capture ncurses shell output in PHP

查看:242
本文介绍了在PHP中捕获ncurses shell输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我不知道这是否可行,老实说,我倾向于更不可能达到规模的尽头,但是我认为这可能值得一问.

我基本上想知道的是,是否有可能捕获用ncurses在php中渲染的shell输出,以与诸如htop之类的工具一起使用.

我注意到php具有一堆实验性的ncurses函数,但是它们似乎都旨在创建不读取它的内容.理想情况下,我喜欢的东西可能会以

之类的东西结束

$output = ncurses_exec("htop --no-loop");

注意:我知道htop没有--no-loop的选项,但是我添加了它来使程序在第一次渲染(可以清除或保留渲染)后退出,只是出于测试目的

预先感谢

解决方案

有一个解决方案:

使用 Gnu屏幕

将命令发送到以分离模式运行的screen.这是一个简单示例,只是为了帮助您入门:

<?php

// Start screen in detached mode, running htop
`screen  -d -m -S htop_session htop`;

 // let screen and htop start
sleep(1);

// Tell screen to save a screenshot in file 'hardcopy.0'
`screen -p 0 -S htop_session -X hardcopy`;

// Tell screen to quit
`screen -p 0 -S htop_session -X quit`;
?>

<pre>
    <?php print file_get_contents('hardcopy.0'); ?>
</pre>

可以尝试的东西

  • 尝试如何设置更大的屏幕窗口大小

okay so i dont know if this is possible and to be honest im leaning more towards the not possible end of the scale but i thought it might be worth asking.

Basically what i am wanting to know is if it is possible to capture shell output rendered with ncurses in php for use with tools such as htop.

i have noticed that php has a whole bunch of experimental ncurses functions but they all seem to be aimed at creating content not reading it. Ideally id like something where i could end up with something like

$output = ncurses_exec("htop --no-loop");

NOTE: im aware that htop doesnt have an option for --no-loop but i added it to make the program exit after the first rendering (rendering can be cleared or kept) just for testing purposes

Thanks in advance

解决方案

There is a solution:

Use Gnu Screen

Send commands to screen running in detached mode. Here is a quick-and-dirty example just to get you started:

<?php

// Start screen in detached mode, running htop
`screen  -d -m -S htop_session htop`;

 // let screen and htop start
sleep(1);

// Tell screen to save a screenshot in file 'hardcopy.0'
`screen -p 0 -S htop_session -X hardcopy`;

// Tell screen to quit
`screen -p 0 -S htop_session -X quit`;
?>

<pre>
    <?php print file_get_contents('hardcopy.0'); ?>
</pre>

Things to try

  • Experiment how to set a larger screen window size

这篇关于在PHP中捕获ncurses shell输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆