Depends on the platform you are using and the team you are using.
For example, on Unix / Linux, you can add > /dev/null & at the end of the command to tell the shell to free the process you started and exec will return immediately. This does not work on Windows, but there is an alternative approach using a COM object (see below).
Many commands have a command line argument that can be passed, so they release their connection to the terminal and return immediately. In addition, some commands will freeze because they have asked a question and are waiting for user input to let them continue (for example, when gzip started, 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 a question (in the gzip example, you will pass -f ).
EDIT
Here is the code to be done on Windows if COM is available:
$commandToExec = 'somecommand.exe'; $wshShell = new COM("WScript.Shell"); $wshShell->Run($commandToExec, 0, FALSE);
Note that this is the third parameter FALSE , which tells WshShell to start the program, and then returns immediately (the second parameter 0 is defined as the "window style" and is probably pointless here - you can pass any integer value). The WshShell object is documented here . It definitely works, I used it before ...
I also edited above to reflect the fact that & for> for> for /dev/null also requires a switch to /dev/null .
Also added a bit more information about WshShell.
source share