try running this C# code in VS.NET 2003:

using System;

namespace ExitCode
{
class MainClass
{
static int Main(string[] args)
{
return 7;
}
}
}

run it under the debugger, and what do you get?
The program '[4552] ExitCode.exe' has exited with code 0 (0x0).

see? zero, not seven. Is this a bug or what?

Re: This can't be true by Uri

Uri
Thu Mar 24 01:30:31 CST 2005

I tried again, this time from the command line, and checked
%ERRORLEVEL%. This way I do get the correct exit code - so this is an
IDE bug?

Uri Dor wrote:

> try running this C# code in VS.NET 2003:
>
> using System;
>
> namespace ExitCode
> {
> class MainClass
> {
> static int Main(string[] args)
> {
> return 7;
> }
> }
> }
>
> run it under the debugger, and what do you get?
> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>
> see? zero, not seven. Is this a bug or what?

Re: This can't be true by Matt

Matt
Thu Mar 24 14:01:51 CST 2005

Hello Uri,

You need to use Environment.Exit(7).

--
Matt Berther
http://www.mattberther.com

> try running this C# code in VS.NET 2003:
>
> using System;
>
> namespace ExitCode
> {
> class MainClass
> {
> static int Main(string[] args)
> {
> return 7;
> }
> }
> }
> run it under the debugger, and what do you get?
> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
> see? zero, not seven. Is this a bug or what?
>




Re: This can't be true by Anubhav

Anubhav
Sat Mar 26 23:04:40 CST 2005

its working fine, the program completed properly so u got an exit code of 0

"Uri Dor" <tablul@newsgroups.nospam> wrote in message
news:OmVr$IEMFHA.3832@TK2MSFTNGP12.phx.gbl...
> try running this C# code in VS.NET 2003:
>
> using System;
>
> namespace ExitCode
> {
> class MainClass
> {
> static int Main(string[] args)
> {
> return 7;
> }
> }
> }
>
> run it under the debugger, and what do you get?
> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>
> see? zero, not seven. Is this a bug or what?



Re: This can't be true by Uri

Uri
Mon Mar 28 07:40:52 CST 2005

no offense intended to the repliers, but could I get an answer from a
MSFT employee ?

Uri Dor wrote:

> I tried again, this time from the command line, and checked
> %ERRORLEVEL%. This way I do get the correct exit code - so this is an
> IDE bug?
>
> Uri Dor wrote:
>
>> try running this C# code in VS.NET 2003:
>>
>> using System;
>>
>> namespace ExitCode
>> {
>> class MainClass
>> {
>> static int Main(string[] args)
>> {
>> return 7;
>> }
>> }
>> }
>>
>> run it under the debugger, and what do you get?
>> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>>
>> see? zero, not seven. Is this a bug or what?

Re: This can't be true by Pat

Pat
Tue Mar 29 12:42:41 CST 2005

Anubhav is right. The program executed and ended without error, so the
exit code is 0. I don't think that you need a MS employee to explain
that.


Re: This can't be true by Uri

Uri
Wed Mar 30 09:38:41 CST 2005

let me reiterate this to all repliers (so far):
I tried running the code from the command line, and checked
%ERRORLEVEL%. This way I do get the correct exit code (by this I mean 7,
not 0).
The correct exit code is 7, not 0, because that's what my code returns
(either by return 7 or by Environment.Exit(7), which are the same).
The IDE, however, ignores the process exit code and shows 0, which
although being a common convention for a successful process exit code,
was not the actual process exit code.
If anyone still thinks 0 is the right value for the IDE to show - I'm
sorry, I don't think I can make this any clearer.

Uri Dor wrote:
> no offense intended to the repliers, but could I get an answer from a
> MSFT employee ?
>
> Uri Dor wrote:
>
>> I tried again, this time from the command line, and checked
>> %ERRORLEVEL%. This way I do get the correct exit code - so this is an
>> IDE bug?
>>
>> Uri Dor wrote:
>>
>>> try running this C# code in VS.NET 2003:
>>>
>>> using System;
>>>
>>> namespace ExitCode
>>> {
>>> class MainClass
>>> {
>>> static int Main(string[] args)
>>> {
>>> return 7;
>>> }
>>> }
>>> }
>>>
>>> run it under the debugger, and what do you get?
>>> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>>>
>>> see? zero, not seven. Is this a bug or what?

Re: This can't be true by Jon

Jon
Wed Mar 30 11:50:33 CST 2005

Pat A <pwalessi1@gmail.com> wrote:
> Anubhav is right. The program executed and ended without error, so the
> exit code is 0. I don't think that you need a MS employee to explain
> that.

No, Anubhav is *not* right. The return value from Main is used as the
exit code if you use the version which returns an int.

For instance, try this:

using System;

class Test
{
static int Main()
{
return 5;
}
}

Run that from the command line, and then type

echo %ERRORLEVEL%

- it will display 5.

That's one of the supported ways of exiting a program with a specific
exit code. It's unfortunate that the debugger doesn't seem to support
it properly.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: This can't be true by Jon

Jon
Wed Mar 30 11:53:35 CST 2005

Uri Dor <tablul@newsgroups.nospam> wrote:
> try running this C# code in VS.NET 2003:
>
> using System;
>
> namespace ExitCode
> {
> class MainClass
> {
> static int Main(string[] args)
> {
> return 7;
> }
> }
> }
>
> run it under the debugger, and what do you get?
> The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>
> see? zero, not seven. Is this a bug or what?

I suspect it's a limitation of the debugger. It happens to me too, just
so you know you're not going mad :)

My guess is that the debugger is intercepting things, and resetting the
exit code to show that *it* exited cleanly. Not terribly helpful though
:(

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: This can't be true by Uri

Uri
Wed Apr 06 04:34:09 CDT 2005

Thanks, Jon, from the depth of my remaining sanity :-)


Jon Skeet [C# MVP] wrote:
> Uri Dor <tablul@newsgroups.nospam> wrote:
>
>>try running this C# code in VS.NET 2003:
>>
>>using System;
>>
>>namespace ExitCode
>>{
>> class MainClass
>> {
>> static int Main(string[] args)
>> {
>> return 7;
>> }
>> }
>>}
>>
>>run it under the debugger, and what do you get?
>>The program '[4552] ExitCode.exe' has exited with code 0 (0x0).
>>
>>see? zero, not seven. Is this a bug or what?
>
>
> I suspect it's a limitation of the debugger. It happens to me too, just
> so you know you're not going mad :)
>
> My guess is that the debugger is intercepting things, and resetting the
> exit code to show that *it* exited cleanly. Not terribly helpful though
> :(
>