从VB.net中的退出进程获取错误代码(退出代码) [英] Get Error Code (Exit Code) from Exited Process in VB.net

查看:185
本文介绍了从VB.net中的退出进程获取错误代码(退出代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我想使用VB.net来执行程序(* .exe文件),等到它完成并获得* .exe程序返回的返回值。现在我使用下面的代码完成了这个,但是我得到的前几次尝试的错误代码是正确的,但后来我继续得到0xCDCDCDCD作为错误代码。我不明白为什么运行此代码会在几次尝试后生成错误的结果。请帮忙。

我如何确保获得正确的退出代码

Ps。 * .exe文件是用c ++编写的,它总是返回一个正整数,其中0xCDCDCDCD为负数,作为有符号整数表示



代码:

  Dim  startInfo  As   System.Diagnostics.ProcessStartInfo 
Dim MyProces As 处理

startInfo.FileName = myExeFileName
startInfo.Arguments = myExeArgString
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden

MyProces = Process.Start(startInfo)
MyProces.WaitForExit( )

如果(MyProces.ExitCode<> 0 然后
MsgBox( 0x + Hex(MyProces.ExitCode()))
结束 如果

解决方案

流程 class有一个 ExitCode 属性。 此处示例 [ ^ ]。



我认为这就是你所需要的。 :)

Hi. I want to use VB.net to execute a program (*.exe file), wait till it finishes and get the return value the *.exe program returns. Now I did accomplish this using the code bellow however the error code i get the first few tries is correct but then i keep getting 0xCDCDCDCD as the error code. I don't understand why running this code would generate the wrong result after few tries. Please help.
How can i ensure i get the correct exit code
Ps. the *.exe file was writen in c++ and it always returns a positive integer where as 0xCDCDCDCD is negative as a signed integer representation

CODE:

Dim startInfo As New System.Diagnostics.ProcessStartInfo
Dim MyProces As Process

startInfo.FileName = myExeFileName
startInfo.Arguments = myExeArgString
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden

MyProces = Process.Start(startInfo)
MyProces.WaitForExit()

If (MyProces.ExitCode <> 0) Then
  MsgBox("0x" + Hex(MyProces.ExitCode()))
End If

解决方案

The Process class has an ExitCode property. Example here[^].

I think that is what you need. :)


这篇关于从VB.net中的退出进程获取错误代码(退出代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆