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?

user3761555
  • 851
  • 10
  • 21
  • 4
    yes `echo %errorlevel%` – Gerhard Mar 18 '19 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` – Gerhard Mar 18 '19 at 10:22

1 Answers1

1

This works:

dotnet HelloExceptionDotnetCore.dll
echo %errorlevel%
exit %errorlevel%
user3761555
  • 851
  • 10
  • 21
  • 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_. – Gerhard Mar 19 '19 at 05:48