【问题标题】:Start-Job not producing expected output [duplicate]Start-Job 没有产生预期的输出[重复]
【发布时间】:2017-12-24 19:32:29
【问题描述】:

为什么在下面的代码中,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'

The code above yields this ouput

【问题讨论】:

    标签: powershell scripting


    【解决方案1】:

    如果您删除$ScriptBlockForJob 中的最后一行,则该命令将按预期运行。

    $ScriptBlockForJob = {    
        Get-ChildItem $Input -Directory `
            | Where-Object `
                {$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0}                               
    }
    

    Output as expected

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多