Avatar of Jimbo99999
Jimbo99999
Flag for United States of America asked on

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
Visual Basic.NET

Avatar of undefined
Last Comment
Jimbo99999

8/22/2022 - Mon
SOLUTION
Anil Golamari

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike Tomlinson

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

Jimbo99999

ASKER
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
ASKER CERTIFIED SOLUTION
Mike Tomlinson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jimbo99999

ASKER
Good Idea Mik...I will try that out now.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Jimbo99999

ASKER
It is working great now.

Thanks for the help,
jimbo99999