×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Returning a value from EXE

Returning a value from EXE

Returning a value from EXE

(OP)
Colleagues,
I have "Manager" EXE which calls "Worker" EXE.
That latter has to return a value to the calling "Manager" (say, numeric success code, or just Boolean one).
Will (in the "Worker")

CODE --> .NET

Sub Main() As Integer
Dim lnSuccess As Integer = 0 ' Full success, initially
...
Return lnSuccess
End
End Sub 

do the trick?

Regards,

Ilya

RE: Returning a value from EXE

Environment.ExitCode I believe

RE: Returning a value from EXE

Yes

RE: Returning a value from EXE

That'll show me to always pay attention. No, I didn't mean Environment.Exit(int32 exitCode)

I meant exactly what I said: Environment.ExitCode

RE: Returning a value from EXE

(OP)
Hmmm... Am I correctly understand that in VB .NET

1. Parameters passed by the calling EXE shall be read by Environment.GetCommandLineArgs() method,
2. Property Environment.ExitCode is read by the calling EXE upon the called one's "retired"?

If so - then another, more complex scenario:
Imagine that Master.EXE calls more than 1 Worker, say Worker1.EXE and Worker2.EXE (and so on, up to, say, 12 Workers);
How the Master.EXE knows which WorkerN.EXE finished its run and returns that ExitCode?
(I looked up Environment class' description and found nothing that tells me the name of the called EXE bound to the returned ExitCode...)

Regards,

Ilya

RE: Returning a value from EXE

Not to state the obvious, but I would assume your EXE's deal with some kind of the data base.
If so, then why not just write what you want into a table and read anything anywhere from that table... ponder


---- Andy

There is a great need for a sarcasm font.

RE: Returning a value from EXE

(OP)

Quote (Andrzejek)

I would assume your EXE's deal with some kind of the data base
No, Andy, there's no DB/table to "supervise" the "Workers".

There is the solution, though: since Workers run each in its own subdir, each Worker creates a TXT (pure ASCII) file and, on exiting, writes the exit code into this file.
This is the solution used in our programs so far. But IMHO this solution is kinda clumsy... and I'm trying to find something better than that.
(In case you are wondering: I'm programming Master to have an array to keep track of the Worker.EXE copies launched, but like I've said: there's no table to "keep and eye" on Workers.)

Regards,

Ilya

RE: Returning a value from EXE

>How the Master.EXE knows which WorkerN.EXE

How are you launching the Workers?

This code, for example, essentially illustrates being able to track each worker uniquely plus getting the exit code from each one
You'll need a form with two buttons on it. Remember, it illustrates some ideas; it is NOT production code.

CODE

Imports System.Threading
Public Class Form1
    Dim myproc As System.Diagnostics.Process

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        myproc = System.Diagnostics.Process.Start("<pathtoexeinstanceofthisveryapplication") ' launch another copy of myself

        AddHandler myproc.Exited, AddressOf Proc_Exit
        MsgBox("Starting " & myproc.Id) ' Unique ID for this process
        myproc.EnableRaisingEvents = True
        Dim worker As Thread = New Thread(New ThreadStart(Sub() myproc.WaitForExit())) ' spawn a thread so we don't block to monitor for process exit

    End Sub

    Private Sub Proc_Exit(sender As Object, e As EventArgs)
        Dim proc = DirectCast(sender, System.Diagnostics.Process)
        MsgBox("Stopping " & proc.Id & " Exit code: " & proc.ExitCode & " Named: " & proc.StartInfo.FileName) ' Various bits of info about uniquely identifiable  exiting process
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Environment.ExitCode = 256
    End Sub
End Class 

RE: Returning a value from EXE

(OP)
Threading, IOW, right?
Unfortunately, I've never done multi-threaded programs... but, as James Bond said in "The Spy Who Loved Me", "There's 1st time for everything"!
And I've never shied away from learning some new programming technique.
thanks

Regards,

Ilya

RE: Returning a value from EXE

Er, well no not really - threading is not the point here. I included it as it was going to be the basis of a more complex, bigger solution (involving polling waitable events ...), but I decided against that. You can actually comment out the Dim Worker line, and the code will still work fine.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close