dongpengqin3898 2014-01-17 16:35
浏览 88
已采纳

在PHP中捕获ncurses shell输出

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

  • 写回答

1条回答 默认 最新

  • doulv1760 2014-01-17 17:40
    关注

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog