在我们的脚本中,我可以做以下事情:

$output = myexternalcommand
write-output $output

这有效。但是,仅在外部程序完成运行后才显示输出。尽管外部程序会定期转储状态,但没有指示脚本中正在发生什么。

我想知道是否有一种方法可以在运行时显示外部程序的输出。问候。

最佳答案

使用 Tee-Object 将外部命令的输出发送到两个方向。根据文档,


cmd /c "dir /s c:\windows\system32" | Tee-Object -Variable foobar
# dir list is printed and result is also stored in $foobar
$foobar.Count # will return the dir cmd's output as an Object[]

10-07 18:59
查看更多