PHP executes command and log output without waiting

I use exec () to execute a command, either linux or windows.

How do you execute linux and windows command and register output without waiting?

I know for linux so as not to wait for an exit: command* > /dev/null 2>/dev/null &

And to output the log for linux: command* > /path/to/log.txt 2>/path/to/error.txt

How could you keep a log and install it in the background in one command? What do windows look like too?

+5
source share
1 answer

On Linux, you can:

exec('command* > /dev/null 2>/dev/null &');

On Windows, you can:

pclose(popen('start /B cmd /C "command* >NUL 2>NUL"', 'r'));

Both examples disable output and errors that go to /dev/null(linux) or NUL(windows), which means they are stored "nowhere."

You can replace them with valid paths in your system.

Linux a & . start cmd, .

+12

All Articles