start external command and close powershell before completion

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Albert van Boerum Albert van Boerum 1 year, 8 months ago.

  • Author
    Posts
  • #23419
    Profile photo of John Mooper
    John Mooper
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Yep, use the Start-Process cmdlet.

  • #23421
    Profile photo of John Mooper
    John Mooper
    Participant

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

  • #23458
    Profile photo of Albert van Boerum
    Albert van Boerum
    Participant

    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.