1

When ran through php's shell_exec, following code does not respect nohup:

root@N76 ~
$ php -r "echo exec('nohup sleep 5 > NUL 2>&1 &');"
(5 seconds later)
root@N76 ~

When executed in terminal/command line, it works as expected:

root@N76 ~
$ nohup sleep 5 > NUL 2>&1 &
[1] 12176
root@N76 ~

Is this expected behavior for POSIX like environment on Windows, or I'm doing something wrong (except running this on Windows)?

Dejan Marjanović
  • 19,244
  • 7
  • 52
  • 66
  • Related to http://stackoverflow.com/questions/19144869/running-unix-process-in-background-from-php/19145020#19145020 – kojiro Oct 13 '13 at 15:55
  • @kojiro yes and no, I forgot to mention I've tried opening process with various function like exec, shell_exec, popen, system, etc. – Dejan Marjanović Oct 13 '13 at 15:57
  • Did you read the PHP source code for those functions to see if any of them *doesn't* `waitpid`? – kojiro Oct 13 '13 at 15:59
  • @kojiro haven't to be honest, but it works as expected on Linux. Question is a bit vague there is no guarantee it'll work on Windows, altough if there is a "solution", it would be nice to hear it. Thanks. – Dejan Marjanović Oct 13 '13 at 16:03
  • I guess I'm a little confused by the question because Windows doesn't *have* POSIX-like behavior. – kojiro Oct 13 '13 at 16:07
  • Which Windows version? The POSIX like on Windows differs based on versions... . – hakre Oct 13 '13 at 16:08
  • To fork into background, for unix I use `$cmd >/dev/null &` and for windows I use psexec like `psexec /accepteula -d $cmd >%TEMP%\cmd.log 2>&1` – Glavić Oct 13 '13 at 16:10

0 Answers0