[英]no receive-job results for gci when -path is a variable
This returns nothing: 这不返回任何内容:
$x = "C:\temp"
Start-Job -ScriptBlock {get-childItem -path $x} | Wait-Job | Receive-job
But providing the path parameter without a variable, like so... 但是提供没有变量的path参数,就像这样...
Start-Job -ScriptBlock {get-childItem -path C:\temp} | Wait-Job | Receive-job
...returns the contents of that temp folder, durrr.txt in this case. ...在这种情况下,返回该临时文件夹durrr.txt的内容。 This is on Windows Server 2008R2 SP1 with Powershell $host.version output as follows: 这是在Windows Server 2008R2 SP1上,其具有Powershell $ host.version输出,如下所示:
Major Minor Build Revision
----- ----- ----- --------
3 0 -1 -1
Suspecting Powershell's v3, I tried updating a Windows 7 SP1 desktop from v2 to v3, but no luck recreating the problem. 怀疑Powershell的v3,我尝试将Windows 7 SP1桌面从v2更新到v3,但是没有运气会重现此问题。 On that upgraded desktop, $host.version output now matches the above. 在升级后的桌面上,$ host.version输出现在与上面匹配。
What's going on? 这是怎么回事?
EDIT / What was going on? 编辑/发生了什么事?
The busted job seems equivalent to 这份工作似乎等于
Start-Job -ScriptBlock {get-childItem -path $null} | Wait-Job | Receive-job
So gci returned results for the background job's current directory, the Documents folder, which happened to be empty. 因此,gci返回了后台作业的当前目录(Documents文件夹)的结果,该目录恰好为空。
You need to pass argument to the scriptblock 您需要将参数传递给脚本块
$x = "C:\temp"
Start-Job -ScriptBlock {get-childItem -path $args[0]} -argumentlist $x | Wait-Job | Receive-job
In powershell V3 you can do : 在Powershell V3中,您可以执行以下操作:
$x = "C:\windows"
Start-Job -ScriptBlock {get-childItem -path $using:x} | Wait-Job | Receive-job
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.