I'm running PHP on win XP and I'm using exec() for some stuff in my program but every time the exec() is running a cmd.exe window is opened for a few seconds on the server. How can I make it run in the background ?
2 Answers
Prefix the command with start /B.
$process = popen("start /B ". $cmd, "r");
Comments
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run('yourprogpath', 0, false);
Windows only.
EDIT - I think Fraxtil's answer is probably better if it works across windows and unix.
2 Comments
ashastral
My answer doesn't work on Unix, actually. The
start command is Windows-specific. The comment I linked to does provide an OS-agnostic solution, though.Ben
O.k. Probably worth noting that it also opens a file pointer to the process that you can read and write to (could be handy). Will it wait until the procces completes or is it asynchronous? Couldn't really work it out from docs.