how to catch the return code of one VB.Net executable from another VB.net executable

G

Guest

I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not thrown as the program should. here's my code for A.exe

procEXE = Process.Start(PROGRAM_NAME
procEXE.WaitForExit(

If procEXE.HasExited The
If procEXE.ExitCode <> 0 The
Throw New Exception("Process execution failed. Check the server and error logs for more details."
End I
End I

and here is the code for B.exe

Public Function Main(ByVal sArgs() As String) As Intege

Dim sNetUserId As Strin
Dim lReturnCode As Integer = -

Tr

sNetUserId = WindowsIdentity.GetCurrent().Name(

If Not FunctionExecuteSuccessful() Then Exit Functio
lReturnCode =

Catch Ex As Exceptio
HandleClientError(Ex

End Tr

Return lReturnCod

End Functio

Is there something wrong with what I did

thanks
libs
 
C

CJ Taylor

Attach to the Exited event of the process.

libs said:
I have A.exe that should catch the return code of B.exe (both are written
in VB.net) so A.exe can continue processing other commands. but A.exe
cannot catch B's return code so an exception is not thrown as the program
should. here's my code for A.exe:
procEXE = Process.Start(PROGRAM_NAME)
procEXE.WaitForExit()

If procEXE.HasExited Then
If procEXE.ExitCode <> 0 Then
Throw New Exception("Process execution failed. Check the server
and error logs for more details.")
 
C

CJ Taylor

Heh, didn't read the whole thing... just going for a fast response that I've
answered a couple times...

Man rough day for me in the Ng's.
 
G

Guest

i tried that, and also set EnableRaisingEvents to true. didnt work.

was there something wrong with the code? Will having a main() function with return value of integer would cause a return value be caught by ExitCode property?

----- CJ Taylor wrote: -----

Attach to the Exited event of the process.

libs said:
I have A.exe that should catch the return code of B.exe (both are written
in VB.net) so A.exe can continue processing other commands. but A.exe
cannot catch B's return code so an exception is not thrown as the program
should. here's my code for A.exe:
If procEXE.ExitCode <> 0 Then
Throw New Exception("Process execution failed. Check the server
and error logs for more details.")
 
C

CJ Taylor

Where are you calling htis thing from?

libs said:
i tried that, and also set EnableRaisingEvents to true. didnt work.

was there something wrong with the code? Will having a main() function
with return value of integer would cause a return value be caught by
ExitCode property?
 
T

Tom Shelton

I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not thrown as the program should. here's my code for A.exe:

procEXE = Process.Start(PROGRAM_NAME)
procEXE.WaitForExit()

If procEXE.HasExited Then
If procEXE.ExitCode <> 0 Then
Throw New Exception("Process execution failed. Check the server and error logs for more details.")
End If
End If

and here is the code for B.exe:

Public Function Main(ByVal sArgs() As String) As Integer

Dim sNetUserId As String
Dim lReturnCode As Integer = -1

Try

sNetUserId = WindowsIdentity.GetCurrent().Name()

If Not FunctionExecuteSuccessful() Then Exit Function
lReturnCode = 0

Catch Ex As Exception
HandleClientError(Ex)

End Try

Return lReturnCode

End Function


Is there something wrong with what I did?

thanks,
libs

Are these window apps or console apps?
 
G

Guest

A.exe is a service executable. B.exe is a simple executable that generates PDF files. it's got no UI
----- Tom Shelton wrote: ----

I have A.exe that should catch the return code of B.exe (both are written in VB.net) so A.exe can continue processing other commands. but A.exe cannot catch B's return code so an exception is not thrown as the program should. here's my code for A.exe
If procEXE.ExitCode <> 0 The
Throw New Exception("Process execution failed. Check the server and error logs for more details."
End I
End I
lib

Are these window apps or console apps
 
T

Tom Shelton

A.exe is a service executable. B.exe is a simple executable that generates PDF files. it's got no UI.

So A.exe is a service? Hmmm. That may be the problem. Let me do a
little checking.
 
T

Tom Shelton

A.exe is a service executable. B.exe is a simple executable that generates PDF files. it's got no UI.

First - is there anyway you could set the line wraping in your news
reader to something like 78 chars? having your post show up as one big
line of text makes it a little difficult for those of us who live in the
stone age and use text based new clients and editors (slrn and vim in my
case :).

Second :) I'm higly suspicious of the fact that a.exe is a service
application. I'm not an expert on windows services, but I have messed
with them enough to know that the rules are a little different. I have
to wonder - are you sure that b.exe is even being run? Can you
elaborate a little on the symptoms? How do you know that a.exe is not
getting a return code? Are you getting exceptions? And if so what are
they?

And the last thing... Is there some reason that B.exe has to be a
separate process? Why don't you just spawn a thread (probably using
ThreadPool.QueueUserWorkItem)?
 
G

Guest

we found the fix. We should set system.environment.exitcode instead of Main having to return an integer value.

thanks for all your help

----- Tom Shelton wrote: ----


First - is there anyway you could set the line wraping in your new
reader to something like 78 chars? having your post show up as one bi
line of text makes it a little difficult for those of us who live in th
stone age and use text based new clients and editors (slrn and vim in m
case :)

Second :) I'm higly suspicious of the fact that a.exe is a servic
application. I'm not an expert on windows services, but I have messe
with them enough to know that the rules are a little different. I hav
to wonder - are you sure that b.exe is even being run? Can yo
elaborate a little on the symptoms? How do you know that a.exe is no
getting a return code? Are you getting exceptions? And if so what ar
they

And the last thing... Is there some reason that B.exe has to be
separate process? Why don't you just spawn a thread (probably usin
ThreadPool.QueueUserWorkItem)
 

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