Results 1 to 3 of 3

Thread: Return Value from a Console Application

  1. #1
    WellsCarrie's Avatar
    WellsCarrie is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jul 2005
    Location
    Arkansas
    Posts
    95
    Reputation
    115

    Return Value from a Console Application

    I have a console application that seeks data from multiply sources, does some calculations and then loads a data table used by several web sites and reports. When it is run manually, the app works consistently with out unresolved errors.

    However, I need the operations team to run the application via ROBOT (the scheduler we have to use). They refuse to run the application because it does not send a return code of zero when it finishes. With out the return code of Zero Robot reports that the application failed, even when it doesn't.

    So, do any of you know how to get a console app to return a value of zero?

    Thanks,
    Carrie

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,540
    Reputation
    2735
    The system exit code is set to the return value of the function, main, or zero if main returns void. Translated to VB a 'void' method is a Sub method, that is no return value. A default VB.Net console application with a Sub Main will return zero when it finishes, or something else if it fails.
    Here is some code from documentation you can use to check exitcode:
    (change 'filename' to the real path of your or any application.)
    Code:
     
    Dim newProc As Diagnostics.Process = Diagnostics.Process.Start(filename)
    Dim procID As Integer = newProc.Id
    newProc.WaitForExit()
    Dim procEC As Integer = -1
    If newProc.HasExited Then procEC = newProc.ExitCode
    MsgBox("Process with ID " & CStr(procID) & " terminated with exit code " & CStr(procEC))

  3. #3
    WellsCarrie's Avatar
    WellsCarrie is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jul 2005
    Location
    Arkansas
    Posts
    95
    Reputation
    115

    Thanks!

    This worked Great!
    I am running only main(void). So I am exiting with a zero.
    I think there is something wrong on thier end.
    Carrie

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking