繁体   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