为什么在下面的代码中,在作业输出之前显示Read-Host行的输出?
$WorkingDirectory = Get-Location
$ScriptBlockForJob = {
Get-ChildItem $Input -Directory `
| Where-Object `
{$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0} `
| Select-Object FullName
}
Start-Job -InputObject $WorkingDirectory -ScriptBlock $ScriptBlockForJob | Wait-Job | Receive-Job
Read-Host 'Above is a list of empty directories. Press enter to begin deleting them'
答案 0 :(得分:0)
如果您删除$ScriptBlockForJob
中的最后一行,该命令将按预期运行。
$ScriptBlockForJob = {
Get-ChildItem $Input -Directory `
| Where-Object `
{$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0}
}