dongpengqin3898
2014-01-17 16:35 阅读 83
已采纳

在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 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
    点赞 评论 复制链接分享

相关推荐