468,463 Members | 1,906 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

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

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
Nov 20 '05 #1
14 8563
Attach to the Exited event of the process.

"libs" <ld******@removethis.gapac.com> wrote in message
news:F8**********************************@microsof t.com...
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

Nov 20 '05 #2
* "CJ Taylor" <[cege] at [tavayn] dit commmmm> scripsit:
Attach to the Exited event of the process.


Do you know why the OP's code doesn't work?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
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.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "CJ Taylor" <[cege] at [tavayn] dit commmmm> scripsit:
Attach to the Exited event of the process.


Do you know why the OP's code doesn't work?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
> Do you know why the OP's code doesn't work?

No And?

Cor
Nov 20 '05 #5
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Do you know why the OP's code doesn't work?


No And?


Just a question.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
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" <ld******@removethis.gapac.com> wrote in message
news:F8**********************************@microsof t.com...
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


Nov 20 '05 #7
That's all you got huh?

=)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:c6************@ID-208219.news.uni-berlin.de...
* "Cor Ligthert" <no**********@planet.nl> scripsit:
Do you know why the OP's code doesn't work?


No And?


Just a question.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #8
Where are you calling htis thing from?

"libs" <ld******@removethis.gapac.com> wrote in message
news:BC**********************************@microsof t.com...
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" <ld******@removethis.gapac.com> wrote in message
news:F8**********************************@microsof t.com...
> 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


Nov 20 '05 #9
In article <F8**********************************@microsoft.co m>, libs 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:

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?

--
Tom Shelton [MVP]
Nov 20 '05 #10

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

In article <F8**********************************@microsoft.co m>, libs 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
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

lib


Are these window apps or console apps

--
Tom Shelton [MVP

Nov 20 '05 #11
Thats what I'm asking, are you running this within a application loop of
some kind?

"libs" <ld******@removethis.gapac.com> wrote in message
news:A7**********************************@microsof t.com...


A.exe calls B.exe thru a process object.
A.exe checks the ExitCode property of the process object inside the Exited event of process object
----- CJ Taylor wrote: -----

Where are you calling htis thing from?

"libs" <ld******@removethis.gapac.com> wrote in message
news:BC**********************************@microsof t.com...
> 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" <ld******@removethis.gapac.com> wrote in message > news:F8**********************************@microsof t.com...
>> 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
>>>

Nov 20 '05 #12
In article <6A**********************************@microsoft.co m>, libs wrote:

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.

--
Tom Shelton [MVP]
Nov 20 '05 #13
In article <6A**********************************@microsoft.co m>, libs wrote:

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)?

--
Tom Shelton [MVP]
Nov 20 '05 #14
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: ----

In article <6A**********************************@microsoft.co m>, libs wrote
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 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)

--
Tom Shelton [MVP

Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Sunny | last post: by
18 posts views Thread by Simon | last post: by
13 posts views Thread by Woody Splawn | last post: by
20 posts views Thread by Woody Splawn | last post: by
7 posts views Thread by Rob R. Ainscough | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.