Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top