multiprocess - multiprocessing exec's in Powershell up to a threshold -
i have multiple commands in string array invoke ssis packages. take advantage of hardware want run many packages @ once, waiting until 1 completes before adding fray. looking @ other similar questions on think work:
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 } this manage open 6 notepad's, doesn't wait @ threshold - 2 in example. ideally should wait until close 1 of notepad's (i.e. process finishes).
would have done before?
you're close, you're not starting process start-job, get-job , wait-job don't good. work?
$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 }
Comments
Post a Comment