簡體   English   中英

Powershell-捕獲EXE輸出

[英]Powershell - capture EXE output

我編寫了一個腳本來在Powershell中運行Reflect磁盤映像備份。 調用命令來運行Reflect我使用:

& "C:\folders\reflect.exe" -e -w -diff "C:\folders\backup.xml" | Out-Null

這將調用reflect.exe,並在沒有輸出到控制台的情況下啟動備份。 但是,如果沒有Out-Null,則在備份運行時將輸出文本反映到控制台。 有關其執行情況的信息。 當我將命令更改為:

& "C:\folders\reflect.exe" -e -w -diff "C:\folders\backup.xml" | Out-File "C:\logfile.log" -append

要捕獲此輸出,日志文件中沒有任何內容。 我猜這是因為反射輸出到cmd提示符。 我如何獲得這些數據? 我還嘗試了神奇的'2>&1'字符串,並通過反射將其作為參數。

謝謝!

編輯:

這是我的確切代碼:

$loc_reflect = "C:\Program Files\Macrium\Reflect\reflect.exe" # Reflect location
$bak_type = $t # backup type from params 'full' or 'diff'
$dir_scripts = "C:\util\Backups\" # Scripts Dir
$fld_bin = "Bin\" # Path to Bin in scripts dir
$bak_src_norm = "M6600_all.xml" # Backup xml for normal in bin
$bak_args = @('-e', '-w') # array of arguments used in the backup command
[Array]$rargs = $bak_args + @("-$bak_type", "$dir_scripts$fld_bin$bak_src_norm")
& $loc_reflect $rargs | Out-Null

要么

& $loc_reflect $rargs 2>&1 | Out-File "C:\logfile.log" -append

多謝你們!

嘗試以下...

& $loc_reflect $rargs >> "C:\\logfile.log" 2>&1

這是基於對PowerShell輸出重定向的一些快速研究。 盡管Macrium支持論壇上已指出,但是Reflect可能有些尷尬...

http://support.macrium.com/topic.asp?TOPIC_ID=624

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM