2013-05-10 4 views
0

SSIS 패키지를 호출하는 문자열 배열에 여러 명령이 있습니다. 하드웨어를 활용하려면 한 번에 많은 패키지를 실행하고 완료 될 때까지 기다렸다가 다른 패키지를 추가하십시오.PowerShell의 다중 처리 exec의 임계 값이

cls 
$commands = @() 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 

foreach ($instance in $commands) 
{ 
    $running = @(Get-Job | Where-Object { $_.JobStateInfo.State -eq 'Running' }) 
    if ($running.Count -le 2) 
    { 
     Start-Process $instance  
    } 
    else 
    { 
     $running | Wait-Job 
    } 

    Get-Job | Receive-Job 
} 

이 6 개 메모장의를 열고 관리 않지만, 어떤 임계 값에서 대기하지 않습니다 - (2)이 예제에서 : SO에 다른 유사한 질문보고에서이 같은 일이 작동 할 것이라는 점을 생각한다. 이상적으로 메모장 (예 : 프로세스 완료) 중 하나를 닫을 때까지 기다려야합니다.

누구든지 이전에이 작업을 수행 했습니까?

답변

0

당신은 가깝지만 Start-Job으로 프로세스를 시작하지 않으므로 Get-Job과 Wait-Job은 아무런 도움이되지 않습니다. 이게 효과가 있니?

$commands = @() 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 
$commands += "notepad.exe" 

foreach ($instance in $commands) 
{ 
    While ((Get-Job -State Running).Count -ge 2) 
    { Start-Sleep -s 5 } 

    Start-Job -ScriptBlock {Start-Process -FilePath $args[0]} -ArgumentList $instance 
}