Search code examples
phplinuxexecnohup

PHP Exec: Without Waiting, Without Discarding the Output, Without nohup


I need to run a command in PHP like this:

exec('dosomething > saveit.txt');

Except I don't want PHP to wait for it to be complete. I also don't want to throw away the output, and I don't want to use nohup because I'm using that for something else in the same directory.

I also tried pclose(popen('dosomething > saveit.txt','r')); and that didn't work, it still waited.


Solution

  • Add an ampersand to the end of the command, so:

    exec('dosomething > saveit.txt &');