start external command and close powershell before completion

Welcome Forums General PowerShell Q&A start external command and close powershell before completion

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
4 years, 1 month ago.

  • Author
    Posts
  • #23419

    Participant
    Topics: 9
    Replies: 15
    Points: 29
    Rank: Member

    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

    Member
    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    Yep, use the Start-Process cmdlet.

  • #23421

    Participant
    Topics: 9
    Replies: 15
    Points: 29
    Rank: Member

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

  • #23458

    Participant
    Topics: 5
    Replies: 40
    Points: 1
    Rank: Member

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

The topic ‘start external command and close powershell before completion’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort