NServicebus服务时,所以,我有一个PowerShell脚本安装一个NServiceBus服务作为Windows服务。捕获错误安装在PowerShell中
Invoke-Expression "$fullNsbHostPath $arguments"
为了完整起见,我都试过Invoke-Expression
和Start-Process
:
Start-Process -Wait -NoNewWindow -FilePath $fullNsbHostPath -ArgumentList $arguments -RedirectStandardOutput $tempFileName -ErrorVariable $errvar
它会调用安装就好了,这在某些情况下报告异常例如:
Failed to execute installers: System.Data.SqlClient.SqlException
(0x80131904): A connection was successfully established with the
server, but then an error occurred during the login process.
(provider: Shared Memory Provider, error: 0 - No process is on the
other end of the pipe.) ---> System.ComponentModel.Win32Exception
(0x80004005): No process is on the other end of the pipe ... Error
....
Number:233,State:0,Class:20
我对此感到满意。我想预计的例外。然而,这个过程本身并没有表明它失败了。的确,Powershell脚本本身成功完成。
我可以解析为一个错误代码或者一些“例外”文本输出文本,但这似乎可悲的不尽人意。
我不认为这是一个PowerShell的问题。当我通过命令行运行它并检查%errorlevel%
时,我得到0
。此外,其他几个执行相同操作的示例联机脚本也会忽略任何错误传播。
有什么建议吗?
NServiceBus.Host.exe包含捕获所有的异常,然后异常详细信息写入控制台(标准输出,而不是标准错误),不设置退出代码,这么短解析所有输出的代码,我想你”重新卡住了。 –