简体   繁体   中英

Powershell - capture EXE output

I wrote a script to run a Reflect disk image backup in powershell. to call the command to run Reflect I use:

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

This calls the reflect.exe and fires the backup up without output to the console just fine. However, reflect outputs text to the console when the backup runs if there is not Out-Null. Information about what its doing ect. When I change the command to:

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

to capture this output there is nothing in the log file. I am guessing it is because reflect is outputting to the cmd prompt. How can I get that data? I have also tried the magical '2>&1' string and reflect picks it up as a argument.

Thanks!

edit:

Here's my exact code:

$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

or

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

Thanks guys!

Try the following...

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

This is based some quick research on PowerShell output redirection. There may be something awkward with Reflect though as noted on the Macrium support forum...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM