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,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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

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)
        Dim mileage As Integer = proc.ExitCode
        MessageBox.Show("Captured mileage = " & mileage)

Open in new window

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?

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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.

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.
Jimbo99999Author Commented:
It is working great now.

Thanks for the help,
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.