473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 8763
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Sunny | last post by:
Hi, I have a very serious issue at hand. I have created a small C# Console App (Csd.exe) that collects a list of files as its argument and generates their Md5 sets. This application is used by...
6
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of...
18
by: Simon | last post by:
I was of the impression that code placed after a Try...Catch block was only executed if there was no exception thrown. I've got some VB.net code as part of a Windows form that executes even...
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
20
by: Woody Splawn | last post by:
In a message yesterday titled Try Catch Question I got numerous responses. Thank you to all. After all the smoke clears I guess the question is where to place the Return True statement in the...
2
by: CodeSlayer | last post by:
Hi all, This one really has me and the other .Net developers at my work stumped. I have an application that is doing the following: 1 - attempt to validate that user can create a windows task...
34
by: priyanka | last post by:
Hi, I was wondering if we could parse or do something in the executable( whose source language was C). How can I use some scripting language like perl/python to find out the information about...
7
by: Rob R. Ainscough | last post by:
In VB6 I can use Resume Next to execute the line of coding following the line that cause an exception. There doesn't appear to be anything similiar when using Try...Catch -- so how can one resume...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.