Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell 'Start-Job` versus 'Start-Process' [closed]

I'm a little confused about the difference between Start-Job and Start-Process in PowerShell. I know that Start-Job will run in the background, but I'm wondering whether things run differently with Start-Job than with Start-Process and whether there are other implications of using one as opposed to the other . When should you use one over the other, and are there advantages that either has over the other?

like image 713
BlackHatSamurai Avatar asked Jul 30 '13 20:07

BlackHatSamurai


People also ask

What is start-job PowerShell?

The Start-Job cmdlet starts a PowerShell background job on the local computer. A PowerShell background job runs a command without interacting with the current session. When you start a background job, a job object returns immediately, even if the job takes an extended time to finish.

What can you use to start a job in PowerShell other than the start-job command?

The following command starts a job object and saves the resulting job object in the $job variable. Beginning in PowerShell 6.0, you can use the background operator ( & ) at the end of a pipeline to start a background job.

What is AsJob in PowerShell?

Automatic Jobs with -AsJob When the job completes, get the result of the job with Receive-Job . Receive-Job returns the result from the cmdlet as if the -AsJob flag were not present. For example, the Receive-Job result of Do-Action -AsJob is of the same type as the result of Do-Action . Azure PowerShell Copy.

How do I check PowerShell job status?

To get all jobs and their status use the Get-Job PowerShell cmdlet. The command gets the jobs in the current PowerShell session. The output includes a background job, a remote job and several instances of a scheduled job.


1 Answers

Start-Job starts a background job and creates a job object that you use to monitor, query, and interact with the job using the cmdlets Get-Job, Receive-Job, Wait-Job, Stop-Job, and Remove-Job. You won't see any interactive windows or console output until you query the job object with Receive-Job. That's what "background job" means - that it runs, but doesn't interact with the logon session. However, if there's any output, that's collected by the job object, and you can retrieve it with Receive-Job. You can generally tell if there's data to receive by checking the HasMoreData property of the job object, but be careful, that's buggy in PowerShell 2 - remember this? "HasMoreData" is true even after Receive-Job

Start-Process launches a process that runs interactively.

like image 121
Adi Inbar Avatar answered Oct 22 '22 19:10

Adi Inbar