0

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 2

3

Prefix the command with start /B.

$process = popen("start /B ". $cmd, "r");

https://www.php.net/manual/function.exec.php#86329

Sign up to request clarification or add additional context in comments.

Comments

1
$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

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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.