我有一個2個PS函式,顯示某些行程和句柄。我也有寫輸出命令來顯示哪些是行程,哪些是句柄。如何防止在函式的輸出準備好顯示之前彈出這個寫輸出呢?
##Functions。
# -------------------------------------------------------------------------------------------------------
function show-process($PName) /span>{
Write-Output "正在運行的$PName行程是:"。
Get-Process -Name $PName | select ProcessName, @{N='Session ID'/span>; E={$_. SI}}, @{N='Process ID'; E={$_.ID}}, Handles
}
function show-handles($HPath) /span>{
Write-Output "handles that have files open in $HPath : "
handle $HPath
}
# -------------------------------------------------------------------------------------------------------
##開始
# ------------------------------------------------------------------------------------------------------
show-process -PName $CLREXE[/span]。
show-handles -HPath$CLRDIR
目前我得到這個。寫入輸出被顯示在正確的位置。但它并沒有等待函式的輸出。它只是在按下回車鍵后立即顯示寫輸出。但我希望它能等待輸出,然后將寫輸出與函式的輸出一起顯示。
CodePudding
首先,函式回傳值(或者更準確的說是物件)。他們不應該把輸出也寫出來。 其次,你需要將cmdlet的輸出捕捉到變數中,以控制何時顯示結果。##Functions
# ---------------------------------------------------------------------------------
function get-myprocess($PName) /span>{
Get-Process -Name $PName|
選擇ProcessName。
@{name = 'SessionID'; exp = {$_.SI}},
@{name = 'ProcessID'; exp = {$_.ID}},
處理方式
}
function get-filehandle($HPath) {
handle $HPath。
}
# --------------------------------------------------------------------------------
##開始
# --------------------------------------------------------------------------------
$process = get-myprocess -PName $CLREXE
$handle = get-filehandle -HPath -span class="hljs-variable">$CLRDIR
"正在運行的$PName行程是:"。
$process
"在$HPath中打開檔案的處理程式:"
$handle。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/326671.html
標籤:


