VB.Net - Call External EXE with Return value

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
Jimbo99999Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anil GolamariCommented:
sample code in C# but it should return/capture output of exe.

http://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

0
Jimbo99999Author 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
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Mike TomlinsonMiddle School Assistant TeacherCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo99999Author Commented:
Good Idea Mik...I will try that out now.
0
Jimbo99999Author Commented:
It is working great now.

Thanks for the help,
jimbo99999
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.