dotnetcore /批处理脚本退出代码

时间:2019-03-18 10:11:38

标签: powershell batch-file .net-core

我有一个简单的 dotnet核心应用程序:

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;
        }
    }

返回代码很重要,因为作业是从 scheduler 中解雇的(无论您是否使用BMC control-m,autosys,rundeck等)。仅当返回码为1(非零)时,调度程序才会将作业标记为失败。否则,您会从日志中看到错误,但作业状态仍标记为“成功” (应将其标记为“失败”

如果从PowerShell启动作业,则可以使用

dotnet HelloExceptionDotnetCore.dll
echo $LastExitCode

但是我们可以使用常规命令提示符吗?不是 Powershell

1 个答案:

答案 0 :(得分:0)

这有效:

dotnet HelloExceptionDotnetCore.dll
echo %errorlevel%
exit %errorlevel%
相关问题