C# Process.Start (applications return code to OS)

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

I am running an application called AcroComm.exe to poll time clocks here at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will sometimes
stop polling in the middle of the process and terminate. The programing
manual for the app says that it sends a code to the operating system when it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just goes to
the next line of code and continues to poll the next clock. I am using code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned to the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony
 
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an example
of this or point me in the right direction to read it?


Nicholas Paldino said:
Anthony,

You have two options here. The first is to get the Process instance and
call the WaitForExit method. This will block the current thread until the
process has completed.

The second option is to register for the Exited event (make sure you set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
I am running an application called AcroComm.exe to poll time clocks here at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will sometimes
stop polling in the middle of the process and terminate. The programing
manual for the app says that it sends a code to the operating system when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned to
the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony
 
Anthony,

You have two options here. The first is to get the Process instance and
call the WaitForExit method. This will block the current thread until the
process has completed.

The second option is to register for the Exited event (make sure you set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.
 
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


in
message news:[email protected]...
Anthony,

You have two options here. The first is to get the Process instance and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure you set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
I am running an application called AcroComm.exe to poll time clocks here at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned
to
the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony
 
Thanks again... I think I understand now.


Nicholas Paldino said:
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


in
message news:[email protected]...
Anthony,

You have two options here. The first is to get the Process
instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure
you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time clocks
here
at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned
to
the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony
 
Nicholas,

I am curious, I did follow the example which seemed to work and try polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that wasn't.
I am wondering, is this 0 like a bool that lets me know that the process has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I need
the code that is sent to the OS from the application (which could be one of
about 15) I am running from a process.start

Nicholas Paldino said:
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


in
message news:[email protected]...
Anthony,

You have two options here. The first is to get the Process
instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure
you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time clocks
here
at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned
to
the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony
 
Hi,

The value as well as the meaning depend of the application.

A return value of 0 is the standard (inherited from Unix) to indicate a
succesful execution.

do this, create a small command app that only set the return value (
Environment.ExitCode ) and see if your code is reading it correctly.


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Tony said:
Nicholas,

I am curious, I did follow the example which seemed to work and try
polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that
wasn't.
I am wondering, is this 0 like a bool that lets me know that the process
has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I
need
the code that is sent to the OS from the application (which could be one
of
about 15) I am running from a process.start

in
message news:%[email protected]...
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Anthony,

You have two options here. The first is to get the Process instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time clocks here
at
our company. I have written a small C# app that will poll the clocks
based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system
when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command
Line
Parameters")

How can I hook in and see what the code was that the process
returned
to
the
operating system? If you need more info or an exact snipet of code,
please
feel free to ask.

Anthony
 
Tony,

I just tried an example here, and it worked fine. Are you sure that the
code that is returned is the exit code of the process, or is that code
returned in some other manner?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Nicholas,

I am curious, I did follow the example which seemed to work and try
polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that
wasn't.
I am wondering, is this 0 like a bool that lets me know that the process
has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I
need
the code that is sent to the OS from the application (which could be one
of
about 15) I am running from a process.start

in
message news:%[email protected]...
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Anthony,

You have two options here. The first is to get the Process instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time clocks here
at
our company. I have written a small C# app that will poll the clocks
based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system
when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command
Line
Parameters")

How can I hook in and see what the code was that the process
returned
to
the
operating system? If you need more info or an exact snipet of code,
please
feel free to ask.

Anthony
 
Well, I am unsure. The manual states the following: "Acrocomm feeds back the
following codes to the operating system" and then it lists the codes. That
is all it says in that section. It has no further descriptions. There is
also nothing listed before this and the heading of the section is "Error
Codes"!

Nicholas Paldino said:
Tony,

I just tried an example here, and it worked fine. Are you sure that the
code that is returned is the exit code of the process, or is that code
returned in some other manner?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Nicholas,

I am curious, I did follow the example which seemed to work and try
polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that
wasn't.
I am wondering, is this 0 like a bool that lets me know that the process
has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I
need
the code that is sent to the OS from the application (which could be one
of
about 15) I am running from a process.start

in
message news:%[email protected]...
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Anthony,

You have two options here. The first is to get the Process instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time clocks here
at
our company. I have written a small C# app that will poll the clocks
based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system
when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command
Line
Parameters")

How can I hook in and see what the code was that the process
returned
to
the
operating system? If you need more info or an exact snipet of code,
please
feel free to ask.

Anthony
 
Tony,

Is it possible that it does it through the out or err output streams and
not as a return code?

If it doesn't return this value through the return value of the
application, then there has to be some other way. You need to find what
that way is (unless someone else here is familiar with the product in
question).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Well, I am unsure. The manual states the following: "Acrocomm feeds back
the
following codes to the operating system" and then it lists the codes. That
is all it says in that section. It has no further descriptions. There is
also nothing listed before this and the heading of the section is "Error
Codes"!

in
message news:[email protected]...
Tony,

I just tried an example here, and it worked fine. Are you sure that the
code that is returned is the exit code of the process, or is that code
returned in some other manner?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Nicholas,

I am curious, I did follow the example which seemed to work and try
polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that
wasn't.
I am wondering, is this 0 like a bool that lets me know that the
process
has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I
need
the code that is sent to the OS from the application (which could be
one
of
about 15) I am running from a process.start

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Anthony,

You have two options here. The first is to get the Process
instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make
sure
you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time
clocks
here
at
our company. I have written a small C# app that will poll the clocks
based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system
when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am
using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command
Line
Parameters")

How can I hook in and see what the code was that the process
returned
to
the
operating system? If you need more info or an exact snipet of code,
please
feel free to ask.

Anthony
 
I am currently testing the standardError output to see if it may be in
there...


Nicholas Paldino said:
Tony,

Is it possible that it does it through the out or err output streams and
not as a return code?

If it doesn't return this value through the return value of the
application, then there has to be some other way. You need to find what
that way is (unless someone else here is familiar with the product in
question).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Tony said:
Well, I am unsure. The manual states the following: "Acrocomm feeds back
the
following codes to the operating system" and then it lists the codes. That
is all it says in that section. It has no further descriptions. There is
also nothing listed before this and the heading of the section is "Error
Codes"!

in
message news:[email protected]...
Tony,

I just tried an example here, and it worked fine. Are you sure
that
the
code that is returned is the exit code of the process, or is that code
returned in some other manner?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas,

I am curious, I did follow the example which seemed to work and try
polling
a clock that I knew wasn't online and one that was. I got the 0 for
successful for the clock online but I still got a 0 for hte one that
wasn't.
I am wondering, is this 0 like a bool that lets me know that the
process
has
exited on it's own.. If so, that isn't necesarrily what I am wanting, I
need
the code that is sent to the OS from the application (which could be
one
of
about 15) I am running from a process.start

"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?


"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message Anthony,

You have two options here. The first is to get the Process
instance
and
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make
sure
you
set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am running an application called AcroComm.exe to poll time
clocks
here
at
our company. I have written a small C# app that will poll the clocks
based
on information found in a DB. My problem is that AcroComm will
sometimes
stop polling in the middle of the process and terminate. The
programing
manual for the app says that it sends a code to the operating system
when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn't know it, it just
goes
to
the next line of code and continues to poll the next clock. I am
using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command
Line
Parameters")

How can I hook in and see what the code was that the process
returned
to
the
operating system? If you need more info or an exact snipet of code,
please
feel free to ask.

Anthony
 
Back
Top