[英]Powershell live output from an external command
在我们的说明书中,我可以做如下的事情:
$output = myexternalcommand
write-output $output
这有效。 但是,仅在外部程序完成运行后才会显示输出。 虽然外部程序是定期转储状态,但没有迹象表明脚本中发生了什么。
我想知道是否有办法在外部程序运行时显示它的输出。 问候。
使用Tee-Object
将外部命令的输出发送到两个方向。 根据文档,
Tee-Object cmdlet重定向输出,也就是说,它在两个方向上发送命令的输出(如字母“T”)。 它将输出存储在文件或变量中,并将其发送到管道。 如果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[]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.