[英]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.