I have a trivial console app in .net. It's just a test part of a larger application. I'd like to specify the "exit code" of my console app. How do I do this?
Thanks!
I have a trivial console app in .net. It's just a test part of a larger application. I'd like to specify the "exit code" of my console app. How do I do this?
Thanks!
System.Environment.ExitCode
http://msdn.microsoft.com/en-us/library/system.environment.exitcode.aspx
Just return the appropiate code from main.
int main(string[] args)
{
return 0; //or exit code of your choice
}
you can return it from Main if you declare your Main method to return an int, or call Environment.Exit(code)
Use ExitCode if your main has a void return signature, otherwise you need to "set" it by the value you return.
If the Main method returns void, you can use this property to set the exit code that will be returned to the calling environment. If Main does not return void, this property is ignored. The initial value of this property is zero.
Not an answer - the return int's have already gotten that...but a plea for sanity. Please, please define your exit codes in an enum, with Flags if appropriate. It makes debugging and maintenance so much easier (and, as a bonus, you can easily print out the exit codes on your help screen - you do have one of those, right?).
enum ExitCode : int {
Success = 0,
InvalidLogin = 1,
InvalidFilename = 2,
UnknownError = 10
}
int Main(string[] args) {
return (int)ExitCode.Success;
}