start external command and close powershell before completion

This topic contains 3 replies, has 3 voices, and was last updated by  Albert van Boerum 3 years, 3 months ago.

  • Author
  • #23419

    John Mooper

    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

  • #23420

    Dave Wyatt

    Yep, use the Start-Process cmdlet.

  • #23421

    John Mooper

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

  • #23458

    Albert van Boerum

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

You must be logged in to reply to this topic.