Windows shell 有一个 %ERRORLEVEL% 变量,可用于查找已通过 shell 运行的进程的退出代码。因此,我可以在 .bat 文件中使用它来获取我从 .bat 文件中调用的外部脚本的退出代码。我想从我正在调用的进程中返回更丰富的错误信息(首先是堆栈跟踪)。我想从我正在运行的 Python 脚本中返回它,我可以使用 Python 'traceback' 模块来完成。我可以将它保存在 %ERRORLEVEL% 中吗?有没有关于这个变量的文档?
最佳答案
%ERRORLEVEL%
返回程序的退出代码,即它是一个整数值并且没有字符限制。如 wiki document for DOS 中所述:
In DOS terminology, an
errorlevel
is an integer exit code returned by an executable program or subroutine. Errorlevels typically range from 0 to 255.
Windows section of the same document说:
Windows uses 32-bit unsigned integers as exit codes, although the command interpreter treats them as signed.
关于python - Windows shell %ERRORLEVEL% 变量是否有字符限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41153413/