Run executable in powershell without waiting for return

Viewed 2758

This is really basic, but I can't find the answer. The installer sets up my path so that I can just type the command:

ng serve

at the command prompt and the script runs. I don't want to wait for this program to finish (it's a server, after all). How do I launch the same script (it's a CMD script as far as I can tell) from Powershell without waiting for it to finish (and without having to find the source directory for the script)?

1 Answers

If it's acceptable to terminate the server when the PowerShell session exits, use a background job:

In PowerShell (Core) 7+

ng server &

In Windows PowerShell, explicit use of Start-Job is required:

Start-Job { ng server }

Both commands return a job-information object, which you can either save in a variable ($jb = ...) or discard ($null = ...)

If the server process produces output you'd like to monitor, you can use the Receive-Job cmdlet.

See the conceptual about_Jobs topic for more information.


If the server must continue to run even after the launching PowerShell session exits, use the Start-Process cmdlet, which on Windows launches an independent process in a new console window (by default); use the -WindowStyle parameter to control the visibility / state of that window:

Start-Process ng server # short for: Start-Process -FilePath ng -ArgumentList server

Note: On Unix-like platforms, where Start-Process doesn't support creating independent new terminal windows, you must additionally use nohup - see this answer.

Related