8

I have a php file 'run.php' which I'm running from the terminal. Within this file I have the following lines:

exec("open-crawlers $port 2>&1",$out,$code); echo 'hello';

The problem that I'm having is that the terminal hangs after executing the 'exec' command; the program doesn't reach the second line.

Fortisimo
  • 1,012
  • 2
  • 11
  • 26

1 Answers1

16

Try this:

exec("nohup open-crawlers $port >> /tmp/log_file.log 2>&1 &");
echo 'hello';
Book Of Zeus
  • 49,509
  • 18
  • 174
  • 171
  • 1
    Thanks. Your answer inspired my solution,this command worked for me: exec("open-crawlers $port >> error.txt 2>&1 &",$out,$code); – Fortisimo Sep 14 '11 at 11:23
  • 4
    Just a comment in case someone else has the problem I did. You have to both pipe the output to a file as well as the appended "&". If you don't pipe the output, it will hang. Just pipe to /dev/null if you don't care about it. – Brent Dec 18 '12 at 00:47
  • 1
    Love you : ) : ) – Petar Vasilev Jul 21 '18 at 10:05