1

What is the PowerShell v2.0 equivalent to this v3.0 code snippt:

for($i=0; $i -lt $num_jobs; $i++) {
    Write-Host -ForegroundColor Darkgreen "[i] Job" $i "starting..."
    Start-Job -ScriptBlock $insert_data -ArgumentList 'host', 'user', 'pass', 'db', $i, $log_out[$i] | Out-Null;
}

get-job | receive-job -AutoRemoveJob -Wait 

I tried the following without luck

for($i=0; $i -lt $num_jobs; $i++) {
    Write-Host -ForegroundColor Darkgreen "[i] Job" $i "starting..."
    Start-Job -ScriptBlock $insert_data -ArgumentList 'host', 'user', 'pass', 'db', $i, $log_out[$i] | Out-Null;
}

get-job | receive-job -Wait 
get-job | remove-job 

It fails on PowerShell v2.0 with:

Remove-Job : The command cannot remove the job with the 3 session identifier be
cause the job is not finished. To remove the job, first stop the job, or use th
e Force parameter.
4

2 に答える 2

0

これを2つの異なる行で試してください:

get-job | wait-job | receive-job
get-job | remove-job
于 2013-09-27T15:06:14.663 に答える