在 PowerShell 工作流中,以下内容有效:
$strings='one','two','three'
foreach -parallel($string in $strings)
{
"Hello: $string"
}
写这个(没有平行部分)的速记方式是:
$strings='one','two','three'
$strings | `
%{
"Hello: $_"
}
有没有办法使用速记版本,指定它应该并行运行?
最佳答案
不是我能看到的。
%
是作为核心 cmdlet 的 ForEach-Object
的默认别名。工作流中的 foreach -parallel
是一个独立于 cmdlet 并且只能在工作流中调用的工作流事件。在这种情况下,您需要在工作流中将别名设置为 foreach -parallel
以调用工作流事件 - 但在工作流中不允许操作别名 (source)。
关于foreach - PowerShell 的 `ForEach -Parallel` 的简写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26014699/