Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exit code?

0 views
Skip to first unread message

Anthony Shorrock

unread,
Sep 3, 2002, 9:27:57 AM9/3/02
to
How can I return an exit code from my console app. please?

I tried having a:
static int main(string[] args)

and returning
return 1;


but in debug, the console always says
exited with code 0 (0x0).

What do I have to do to send an exit code?

Cheers


Robert Jeppesen

unread,
Sep 3, 2002, 9:49:01 AM9/3/02
to
Strange, I get that too.
From docs:
The Main method can use arguments, in which case, it takes one of the following forms:

static int Main(string[] args)
static void Main(string[] args)
The parameter of the Main method is a string array that represents the command-line arguments. Usually you check for the existence
of the arguments by testing the Length property, for example:

if (args.Length == 0)
{
Console.WriteLine("Please enter a numeric argument.");
return 1;
}

So this should work.
--
Robert Jeppesen
MindCom AB
http://www.mindcom.se/

"Anthony Shorrock" <ashorro...@hotmail.com> wrote in message news:ekobT20UCHA.4092@tkmsftngp11...

Greg Ewing

unread,
Sep 3, 2002, 9:58:44 AM9/3/02
to
Anthony, for some reason the IDE in debug mode doesn't show the return value
from main as the exit code. Using return does work though if you call your
app from from System.Diagnostics.Process.Start or from a batch file. From a
batch file you can check the %errorlevel% just to be sure it is working.
From System.Diagnostics.Process you can check the ExitCode property once
your app exits.

--
Greg
http://www.claritycon.com/

"Anthony Shorrock" <ashorro...@hotmail.com> wrote in message
news:ekobT20UCHA.4092@tkmsftngp11...

0 new messages