0

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

  • I never used `ncurses:exe` but I dare to say that most likely that does NOT produce any usable output on stdout. Just like with commands like `top`: they use the terminal in a different way, not by writing linewise into standard out. Either you can switch that output strategy (`top` offers a specific option for that), or you are out of luck. – arkascha Jan 17 '14 at 16:39
  • That's pretty much what i was thinking would be the case but i was hoping that i was wrong – Matt Indeedhat Holmes Jan 17 '14 at 16:45
  • Question is: why do you use `ncurses_exec`, when you want to read from stdout? – arkascha Jan 17 '14 at 16:49

1 Answers1

1

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
grebneke
  • 4,414
  • 17
  • 24