Console Application - Exit Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mythran

    #1

    Console Application - Exit Code

    What is the correct way to set the exit code from within a console
    application? Currently we do:

    Public Function Main() As Integer
    ...
    Environment.Exi tCode = ...
    Return Environment.Exi tCode
    End Function

    Should we use Environment.Exi tCode And/Or return the exit code?

    Thanks,
    Mythran

  • Herfried K. Wagner [MVP]

    #2
    Re: Console Application - Exit Code

    "Mythran" <kip_potter@hot mail.comREMOVET RAIL> schrieb:[color=blue]
    > What is the correct way to set the exit code from within a console
    > application? Currently we do:
    >
    > Public Function Main() As Integer
    > ...
    > Environment.Exi tCode = ...
    > Return Environment.Exi tCode
    > End Function
    >
    > Should we use Environment.Exi tCode And/Or return the exit code?[/color]

    You do not need to (and IMO should not) set 'Environment.Ex itCode' if you
    return the exit code in the 'Main' function and vice versa.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Mythran

      #3
      Re: Console Application - Exit Code


      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:OPh0NChdGH A.5016@TK2MSFTN GP04.phx.gbl...[color=blue]
      > "Mythran" <kip_potter@hot mail.comREMOVET RAIL> schrieb:[color=green]
      >> What is the correct way to set the exit code from within a console
      >> application? Currently we do:
      >>
      >> Public Function Main() As Integer
      >> ...
      >> Environment.Exi tCode = ...
      >> Return Environment.Exi tCode
      >> End Function
      >>
      >> Should we use Environment.Exi tCode And/Or return the exit code?[/color]
      >
      > You do not need to (and IMO should not) set 'Environment.Ex itCode' if you
      > return the exit code in the 'Main' function and vice versa.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>[/color]

      After performing some tests, I found that setting Environment.Exi tCode does
      nothing when Main is defined as a function (and hence, returns a value). If
      it is defined as a sub, setting ExitCode sets the exit code. So yes, you
      are correct :)

      Thanks,
      Mythran

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Console Application - Exit Code

        "Mythran" <kip_potter@hot mail.comREMOVET RAIL> schrieb:[color=blue]
        > After performing some tests, I found that setting Environment.Exi tCode
        > does nothing when Main is defined as a function (and hence, returns a
        > value). If it is defined as a sub, setting ExitCode sets the exit code.
        > So yes, you are correct :)[/color]

        Note that VS.NET 2003 (and maybe VS 2005) didn't show the correct return
        value when running the project from within the IDE.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Mythran

          #5
          Re: Console Application - Exit Code


          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:%23M5MKdhd GHA.1260@TK2MSF TNGP05.phx.gbl. ..[color=blue]
          > "Mythran" <kip_potter@hot mail.comREMOVET RAIL> schrieb:[color=green]
          >> After performing some tests, I found that setting Environment.Exi tCode
          >> does nothing when Main is defined as a function (and hence, returns a
          >> value). If it is defined as a sub, setting ExitCode sets the exit code.
          >> So yes, you are correct :)[/color]
          >
          > Note that VS.NET 2003 (and maybe VS 2005) didn't show the correct return
          > value when running the project from within the IDE.
          >
          > --
          > M S Herfried K. Wagner
          > M V P <URL:http://dotnet.mvps.org/>
          > V B <URL:http://classicvb.org/petition/>[/color]

          I didn't test running it in the IDE. I had a javascript that ran it and
          display the results of the Exec or Run (whichever one it was) function :)

          Mythran

          Comment

          Working...