Capturing returned value from external application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I have simple windows service (C# code), from which I am calling an external
console application created in C#. This console application will return
different integer values that are some error codes.

How do I call this console application from windows service so that I can
read the values returned from the console application.

I have seen a lot of code to call external application, but none of them
mentions how to capture the returned code.

Thanks
pradeep_Tp
 
I have simple windows service (C# code), from which I am calling an
external
console application created in C#. This console application will return
different integer values that are some error codes.

How do I call this console application from windows service so that I can
read the values returned from the console application. [...]

A process has an exit code, which is the value returned by the main
function. You can retrieve it from the Process.ExitCode property once the
process has exited.

If by "return" you don't really mean "return", but rather than the console
application writes the exit codes as text to the standard output, then
instead you can read the standard output by redirecting it. Again, use
the Process class to do this (see ProcessStartInfo.RedirectStandardOutput
and Process.StandardOutput properties).

Pete
 
Thank you Peter. This is what I was looking for :).

Peter Duniho said:
I have simple windows service (C# code), from which I am calling an
external
console application created in C#. This console application will return
different integer values that are some error codes.

How do I call this console application from windows service so that I can
read the values returned from the console application. [...]

A process has an exit code, which is the value returned by the main
function. You can retrieve it from the Process.ExitCode property once the
process has exited.

If by "return" you don't really mean "return", but rather than the console
application writes the exit codes as text to the standard output, then
instead you can read the standard output by redirecting it. Again, use
the Process class to do this (see ProcessStartInfo.RedirectStandardOutput
and Process.StandardOutput properties).

Pete
 
Back
Top