VB.Net - Call External EXE with Return value

Jimbo99999
Jimbo99999 used Ask the Experts™
on
Good Day Experts!

I am not sure how to accomplish the end task for my project.  I am calling an exe using the following code from a testing project which will mimic calling from a current production project.

Dim pHelp as New ProcessStartInfo
phelp.FileName = "C:\Testing\WindowsApplication5.exe"
pHelp.Arguments = "44070,44145,21"
pHelp.UseShellExecute = False
pHelp.WindowsStyle = ProcessWindowStyle.Normal
Dim proc as Process = Process.Start(Help)

The exe produces the mileage between 2 zipcodes.  I have the mileage showing in a messagebox coded in the exe.

The trouble I have now is that I cannot figure out how to get that mileage returned back to my calling testing project.
The code from the exe is contained in Sub Main() within Module MainMod.  

Can you offer any suggestions?

Thanks for the help,
jimbo99999
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
sample code in C# but it should return/capture output of exe.

http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
I have the mileage showing in a messagebox coded in the exe.

Pass that computed mileage to the Environment.Exit() method:
        Dim mileage As Integer = 911
        Environment.Exit(mileage)

Open in new window


Now, in your calling program, wait for the called application to exit and then grab the ExitCode:
        Dim proc As Process = Process.Start(pHelp)
        proc.WaitForExit()
        Dim mileage As Integer = proc.ExitCode
        MessageBox.Show("Captured mileage = " & mileage)

Open in new window

Author

Commented:
Hey There Experts!

Ok, this is exciting I have the mileage getting back to my test calling project.

However, I have been unable to get it back with the decimal point.  

Do you all know if it is possible to do that?

Thanks,
jimbo99999
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
Depends on which approach you're using...

For my solution using Environment.Exit(), pick a precision and pass out the number as an integer; then divide by a factor of ten to move the decimal place back again.

For example, if your mileage was 22.34 miles, you'd return 2234 and then divide by 100 in the calling program to convert it back to decimal.

Author

Commented:
Good Idea Mik...I will try that out now.

Author

Commented:
It is working great now.

Thanks for the help,
jimbo99999

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial