views:

281

answers:

3

how can I provide feedback for a shell command that may run for quite some time?

for example, i need a script that does hg clone ... then in my php i make a call

exec('hg clone ...', $output, $return_value);

but I wouldn't be able to get the output before the command actually ends. It is stated in the documentation ( http://www.php.net/manual/en/function.exec.php ) that

Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

would it mean I should change my command to something similar to

exec('hg clone 2>&1 $some_file', $output, $return_value);

do I need the ampersand symbol at the back of the command to make it work in background? and can I use information $some_file to provide feedback to the user?

+1  A: 

popen:

http://php.net/popen

PS popen works fine with AJAX

dfa
A: 

http://php.net/ob_start

smoove666
+1  A: 

Have a look at another answer I gave to a similar question

soulmerge