开发者

powershells' stuck jobs

I'm trying to make jobs with powershell but they get stuck for a reas开发者_运维百科on.

Untitled2.ps1:

$A = "papa"
$B = "mama"

Start-Job -ScriptBlock { MainHA $args[0] $args[1] } -ArgumentList @($A, $B) -InitializationScript { . "C:\Tools\Untitled3.ps1" }

While (Get-Job -State "Running")
{

    write-host Still working...
    Get-Job | Receive-Job
    Start-Sleep 1
}
Get-Job | Receive-Job
Remove-Job *

Untitled3.ps1:

Function MainHA ($x, $y)
{
    write-host $x, $y
}

Any idea?


Are there any other jobs running?

One way to wait for the specific job you are starting is to store the job you start in a variable.

$job = Start-Job -ScriptBlock { MainHA $args[0] $args[1] } -ArgumentList @($A, $B) -InitializationScript { . "C:\Tools\Untitled3.ps1" }

While ($job.State -eq "Running") {
    write-host Still working...
    Receive-Job $job
    Start-Sleep 1
}
Receive-Job $job
Remove-Job $job
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜