Skip to content

Setting Environment.ExitCode = 1; doesn't work #700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adamfk opened this issue Feb 8, 2023 · 1 comment · Fixed by #712
Closed

Setting Environment.ExitCode = 1; doesn't work #700

adamfk opened this issue Feb 8, 2023 · 1 comment · Fixed by #712

Comments

@adamfk
Copy link

adamfk commented Feb 8, 2023

I can set Environment.ExitCode properly, but it isn't respected when the script exits.

Here's a simple reproduction:
image

The below works though.

Environment.Exit(1);
adamfk added a commit to StateSmith/StateSmith that referenced this issue Feb 8, 2023
@filipw
Copy link
Member

filipw commented Feb 8, 2023

Thanks for the report, this is indeed not supported at the moment, though we could pick it up and override the return code if Environment.ExitCode is different than 0. I am not sure if this will not break some edge cases though.

The alternative that you can use return 1; at any place in the top-level code of the script as behind the scenes it gets wrapped into method returning a status code.

if (Args[0] == "foo")
    return 127;

Console.WriteLine("done");

An even quirkier thing is that you can just place an int (or a method call returning an int) at the end of the script, and that gets converted into a status code too (though that only works at the end)

Console.WriteLine("done");
127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants