Running an executable from my .Net code

  • Thread starter Thread starter STom
  • Start date Start date
S

STom

I am trying to find a way to run a .Net executable from within my vb.net
code. I need to pass parameters into the executable and wait for a return
and check the return value for an error before continuing.

Is this possible to do?

STom
 
Hi,

Take a look at the process class's waitforexit method and process
startinfo.

http://msdn.microsoft.com/library/d...stemdiagnosticsprocessstartinfoclasstopic.asp

http://msdn.microsoft.com/library/d...emdiagnosticsprocessclasswaitforexittopic.asp

Ken
----------------------
I am trying to find a way to run a .Net executable from within my vb.net
code. I need to pass parameters into the executable and wait for a return
and check the return value for an error before continuing.

Is this possible to do?

STom
 
STom said:
I am trying to find a way to run a .Net executable from within my vb.net
code. I need to pass parameters into the executable and wait for a return
and check the return value for an error before continuing.

\\\
Imports System.Diagnostics
..
..
..
Dim psi As New ProcessStartInfo()
With psi
.FileName = "foo.exe"
.Arguments = ...
End With
Dim p As Process = Process.Start(psi)
p.WaitForExit()
MsgBox(CStr(p.ExitCode))
///
 
Herfried,

Thanks for your sample. Here are some other questions...

1. If I have 3 string arguments that I want to pass to the executable, with
the .Arguments, is the syntax like :
..Arguments = "one two three" ?

I will have these 3 arguments in string variables already within my coded.

2. Will the ExitCode be a numeric value that I can set within my executable
to return in case there is a failure or is it some generic error number?

Thanks again.

STom
 
STom said:
1. If I have 3 string arguments that I want to pass to the executable,
with the .Arguments, is the syntax like :
.Arguments = "one two three" ?
Yes.

2. Will the ExitCode be a numeric value that I can set within my
executable to return in case there is a failure or is it some generic
error number?

You can return an integer value. You can make your 'Sub Main' a function
with 'Integer
 
Addendum:

Herfried K. Wagner said:
You can return an integer value. You can make your 'Sub Main' a function
with...

.... 'Integer' return type and the use 'Return <return value>' to return a
certain value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top