0

I would like to run a shell command that runs a process for a very long time, and outputs text while it is executing. This command is run using nohup in the background.

I would like to launch this command in php using shell_exec, but I would like to know the best way to capture the output of this command while it is executing so that my php shows output while it is executing and does not wait indefinitely until the process terminates to show the output.

Example:

shell_exec(nohup ./program.sh &)

user1371011
  • 193
  • 3
  • 12
  • 1
    With an ordinary exec you can only have either or. Create a named pipe, send the output there, and poll from your application -- if you really need to. – mario Jul 25 '12 at 00:32
  • 1
    What mario said. See [this answer](http://stackoverflow.com/questions/11461929/how-to-capture-and-feed-telnet-using-php-and-shell-scripting/11462845#11462845) for an example of using [proc_open](http://php.net/proc_open) to read and write to an active process. This or [popen](http://php.net/popen) is what you need to use. – drew010 Jul 25 '12 at 00:34
  • 2
    you can pipe the output into a log-file, and then read the log. – Nir Alfasi Jul 25 '12 at 00:41
  • how would I make php constantly check the log to see if its been changed and therefore output the contents of the file if necessary, sample code would help! – user1371011 Jul 25 '12 at 02:26

0 Answers0