从 PowerShell 调用 exe 并获取有关成功或失败的反馈 [英] Invoke an exe from PowerShell and get feedback on success or failure
问题描述
如何在 PowerShell 中运行可执行文件并通过 if 语句确定它是成功还是失败?
How can I run an executable in PowerShell and through an if statement determine whether it succeeded or failed?
更具体地说,我试图让 devenv.exe 从 PowerShell 脚本构建解决方案,我需要知道它是成功还是失败.失败,我的意思是构建失败,我假设 devenv 正在向 shell 发送一些东西(可能在 stderr
流中?)
More specifically I'm trying to get devenv.exe to build a solution from a PowerShell script and I need to know whether it succeeded or failed. By failed, I mean that the build has failed and I'm assuming devenv is sending something out to the shell (possibly in the stderr
stream?)
我尝试使用 &
、Invoke-Expression
和 Invoke-Item
并设法让它们全部运行 exe.但我永远无法获得关于成功/失败的反馈.
I tried using &
, Invoke-Expression
and Invoke-Item
and managed to get all of them to run the exe. But I was never able to get feedback on success / failures.
推荐答案
您是否尝试过使用 $LASTEXITCODE
变量?它将包含最后调用的 .exe 的退出代码.
Have you tried using the $LASTEXITCODE
variable? It will contain the exit code of the last .exe that was invoked.
这篇关于从 PowerShell 调用 exe 并获取有关成功或失败的反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!