Reputation: 101
I seem unable to set the exit code of a dotnet core console application such that the expected behaviour is observed on RHEL7. I am using dotnet 2.0.3.
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Environment.Exit(12345);
}
}
}
On windows, the error level is set correctly when executing the program with
dotnet HelloWorld.dll
echo %errorlevel%
12345
On RHEL7, this is not what is seen
dotnet HelloWorld.dll
echo $?
57
I have tried various ways to return an exit code (setting the Environment.ExitCode property, returning an integer from the program) but have had no success.
I will try a test on the latest dotnet core version (2.1.302) as soon as possible but posting this question in the meantime.
Does anyone know what's going on here?
Thanks
Upvotes: 3
Views: 1573
Reputation: 101
I found the problem in the end - it was because on RHEL7, unlike Windows, the exit code/error level is restricted to being an 8 bit integer. I'll need to keep my exit codes in the range [0,255].
Upvotes: 6