Get return code and text from console application.

  • Thread starter Thread starter Shawn
  • Start date Start date
S

Shawn

I have not done a lot of work with console applications, but here is what I
am trying to do.

I wrote a Windows Service (VB.NET 2.0) that will make calls to console apps
(also VB.NET 2.0) that I will be writing. I want to return the exit code and
if there is an error, the error text, so I can have the main app send that
through email and to a database. I can't find a way to do this.

Thanks
 
I have not done a lot of work with console applications, but here is what I
am trying to do.

I wrote a Windows Service (VB.NET 2.0) that will make calls to console apps
(also VB.NET 2.0) that I will be writing. I want to return the exit code and
if there is an error, the error text, so I can have the main app send that
through email and to a database. I can't find a way to do this.

Thanks

Well, getting the exit code (assuming your are using a function main and
returning a code) is easy. You can use System.Diagnostic.Process to launch
the app and then check the objects ExitCode property when the app has ended.

As for getting text... Interesting question - since I don't know of a
standard way of doign that :) Not saying there isn't, I just don't know of
it. But, my first inclination - if you are the author of these apps - is for
the parent process to setup an environment for the child process, and then
read a known environment variable if the exit code indicates a failure.
 
Shawn said:
I have not done a lot of work with console applications, but here is what I
am trying to do.

I wrote a Windows Service (VB.NET 2.0) that will make calls to console apps
(also VB.NET 2.0) that I will be writing. I want to return the exit code and
if there is an error, the error text, so I can have the main app send that
through email and to a database. I can't find a way to do this.

Thanks

Putting aside the issues of this within Vista, look at
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
to see how to read a console apps output.
 
Back
Top