tags:

views:

651

answers:

2

Ok, so here's the thing. I need to read the output (the one that you usually see in a linux console). My biggest problem is that I don't need to read the output of a linear execution, but something rather like wget http://ubuntu.com/jaunty.iso and show its ETA.

Also, the work-flow is the following:

S - webserver

C1 - computer1 in S's intranet

C2 - computer 2 in S's intranet

and so on.

User connects to S which connects to Cx then starts a wget, top or other console logging command (at user's request). User can see the "console log" from Cx while wget downloads the specified target.

Is this plausible? Can it be done without using a server/client software?

Thanks!

A: 

Do you have some existing PHP code you're working on?

bucabay
At the moment no, its just the beginning, but I'm afraid I have to switch to something else if I can't read the console output.
Bogdan Constantinescu
A: 

You'll want to use the php function proc_open for this -- you can specify an array of pipes (stdin, which would normally be attached to the keyboard if you were on the console, std out, and stderr, both normally would be printed to the display). You can then control the input/output folw of the given program

So as an example:

$pipes = array();
$pipe_descriptions = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("file", "/tmp/error-output.txt", "a") // stderr is a file to write to
);

$cmd = "wget $url";

$proc_handle = proc_open($cmd, $pipe_descriptions, $pipes);

if(is_resource($proc_handle))
{
   // Your process is running. You may now read it's output with fread($pipes[1]) and fread($pipes[2])
   // Send input to your program with fwrite($pipes[0])
   // remember to fclose() all pipes and fclose() the process when you're done!
Josh
Oh and for the remote access, where S will connect to C(x), set up SSH keys and set "$cmd to: ssh hostname.of.c wget $url"
Josh