Manage background jobs in PowerShell 4 scripts

I have a series of SAS programs that I run in the background using a PowerShell script that was launched from the Task Scheduler.

I would like each program to finish first before starting another.

I tried many different approaches using the examples I found on this site, but none of them work. What I specifically cannot find is the state of a job running in the background, and then use this state in conditional expression to verify that the first program running in the background is completed before the second program starts.

For example, if I use:

$job01 = Start-Job -ScriptBlock { & "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -sysin "D:\EDM\SASPROGRAMS\ABC.sas" -nosplash -log D:\EDM\SASLOGS -work D:\SASWork }

then

Get-Job

I will see that it is $job01completed immediately after release Get-Job, when the SAS program itself takes about 10 minutes.

, , SAS, , ?

+4
1

& . Start-Process -Wait. :

Start-Process -FilePath "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -ArgumentList "-sysin `"D:\EDM\SASPROGRAMS\ABC.sas`" -nosplash -log D:\EDM\SASLOGS -work D:\SASWork" -NoNewWindow

( ) -.

+5

Source: https://habr.com/ru/post/1674995/


All Articles