Capturing returned value from external application

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
 
P

Peter Duniho

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
 
G

Guest

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
 

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

Top