1

I have a simple dotnet core application:

class Program
    {
        static int Main(string[] args)
        {
            try
            {
                throw new ArgumentException("Damn");
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.Message);
                // Error
                return 1;
            }

            // Success
            return 0;
        }
    }

Return code is important as jobs are fired off from scheduler (Whether you use BMC control-m, autosys, rundeck, whatever). Scheduler will mark the job failed only if return code is 1 (Not zero). Otherwise you see errors from log but job status still flagged "Succeeded" (where it should be marked "Failed")

If we launch the job from PowerShell, we can use

dotnet HelloExceptionDotnetCore.dll
echo $LastExitCode

But can we do same with regular command prompt? Not Powershell?

2
  • 4
    yes echo %errorlevel% Commented Mar 18, 2019 at 10:14
  • There is a chance though that your default errorlevel is echo'd before the dotnet app completed, if that is the case, do start "" /wait dotnet HelloExceptionDotnetCore.dll and then echo %errorlevel% in the next line.. This way we wait for the app to finish and return the relevant errorlevel Commented Mar 18, 2019 at 10:22

1 Answer 1

1

This works:

dotnet HelloExceptionDotnetCore.dll
echo %errorlevel%
exit %errorlevel%
Sign up to request clarification or add additional context in comments.

1 Comment

Well, I would suggest if you want to post your own answer, it will be better if you give some more information than just _This Works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.