Possible Duplicate:
php exec command (or similar) to not wait for result
I have a page that runs a series of exec() commands which forces my PHP script to halt alteration until it receives a response. How can I tell exec() to not wait for a response and just run the command?
I’m using a complex command that has a backend system I can query to check the status, so I’m not concerned with a response.
Depends on what platform you are using, and the command you are running.
For example, on Unix/Linux you can append
> /dev/null &to the end of the command to tell the shell to release the process you have started and exec will return immediately. This doesn’t work on Windows, but there is an alternative approach using the COM object (See edit below).Many commands have a command line argument that can be passed so they release their association with the terminal and return immediately. Also, some commands will appear to hang because they have asked a question and are waiting for user input to tell them to continue (e.g. when running
gzipand the target file already exists). In these cases, there is usually a command line argument that can be passed to tell the program how to handle this and not ask the question (in thegzipexample you would pass-f).EDIT
Here is the code to do what you want on Windows, as long as
COMis available:Note that it is the third,
FALSEparameter that tells WshShell to launch the program then return immediately (the second0parameter is defined as ‘window style’ and is probably meaningless here – you could pass any integer value). The WshShell object is documented here. This definitely works, I have used it before…I have also edited above to reflect the fact that piping to
/dev/nullis also required in order to get&to work withexec()on *nix.Also just added a bit more info about WshShell.