Author Posts

March 17, 2015 at 4:05 am

Hello everyone. Is there way to start external command from Powershell and exit PSH before the external command finishes?
I have a php script, which is executed via php.exe, say something like "C:\PHP\php.exe script.php".
I need to run this command, but not wait until it completes. I've tried using jobs, but the job only executes in the current PSH session, so if I do something like:

powershell.exe -Command {$exe = 'C:\php\php.exe'; $arg1 = 'C:\scripts\script.php'; Start-Job {&$args[0] $args[1]} -ArgumentList @($exe, $arg1)}

it will fail, since PSH exits and the job won't run.

That PHP script can run for couple of minutes, but I need to just start the process and exit Powershell and don't wait for completion. Can that be done?

Thanks in advance

March 17, 2015 at 4:07 am

Yep, use the Start-Process cmdlet.

March 17, 2015 at 4:23 am

Thanks Dave, that worked. Totally forgot about Start-Process.

March 18, 2015 at 7:39 am

That's the beauty of powershell. If you ask the right question, the answer is not far away:

"but I need to just start the process...."