2011-08-24 51 views
0

我試圖用powershell作業,但他們卡住的原因。powershells的卡住的作業

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 
} 

任何想法?

+0

我的答案有幫助嗎?如果不是,你解決了這個問題嗎? (如果有的話,你應該發佈自己的答案) – Rynant

回答

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