我很痛苦地无法从作业中获得任何输出-以下代码有什么问题?
$test = {
DIR
}
$mjob = Start-Job -ScriptBlock {$test}
while (Get-Job -State Running){}
Receive-Job -Job $mjob -OutVariable $otest
Write-Host($otest)
最佳答案
当您使用-OutVariable
时,仅提供变量名称,例如:
... -OutVariable otest
除非
$otest
恰好包含要将输出保存到的变量的名称。其他一些建议。
$test
代表一个脚本块,因此您无需在其周围放置{}
。而不是等待使用while循环,只需使用Wait-Job
例如:$test = { get-childitem }
$job = Start-Job $test
Wait-Job $job
Receive-Job $job -OutVariable otest
$otest
关于powershell - 从工作中获取输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12897823/