powershell能不能运行linux,Powershell可以并行运行命令吗?

史蒂夫汤森的回答在理论上是正确的,但在实践中却没有,正如@likwid指出的那样。我修改后的代码考虑了工作环境障碍 -默认情况下没有任何障碍超越这个障碍!因此,自动$_变量可以在循环中使用,但不能直接在脚本块中使用,因为它位于作业创建的单独上下文中。

要将变量从父上下文传递到子上下文,请使用-ArgumentList参数on Start-Job发送它并param在脚本块内部使用它来接收它。cls# Send in two root directory names, one that exists and one that does not.# Should then get a "True" and a "False" result out the end."temp", "foo" | %{

$ScriptBlock = {

# accept the loop variable across the job-context barrier

param($name)

# Show the loop variable has made it through!

Write-Host "[processing '$name' inside the job]"

# Execute a command

Test-Path "\$name"

# Just wait for a bit...

Start-Sleep 5

}

# Show the loop variable here is correct

Write-Host "processing $_..."

# pass the loop variable across the job-context barrier

Start-Job $ScriptBlock -ArgumentList $_}# Wait for all to completeWhile (Get-Job -State "Running") { Start-Sleep 2 }# Display output from all jobsGet-Job | Receive-Job# CleanupRemove-Job *

(我通常喜欢提供PowerShell文档的参考作为支持证据,但是,唉,我的搜索没有结果。如果您碰巧知道上下文分离的记录,请在此发表评论以告诉我!)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值