powershell'陷入困境

时间:2011-08-24 17:26:03

标签: powershell

我正在尝试使用PowerShell创作工作,但他们因某种原因而陷入困境。

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
}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

还有其他工作正在运行吗?

等待您开始的特定工作的一种方法是将您开始的工作存储在变量中。

$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