python - Windows shell %ERRORLEVEL% 变量是否有字符限制?

标签 python windows batch-file error-handling cmd

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/

相关文章:

windows - 如何使用 cmd 在最小化窗口中启动 Windows 10 应用程序?

batch-file - GnuWin32 openssl s_client 连接到 WebSphere MQ 服务器未在 EOF 关闭,挂起

python - 缩进错误 : expected an indented block python 3. 6

Python 列表理解,具有独特的项目

windows - Windows 批处理文件的文件大小和行长度限制

windows - 自动运行.inf : how to get drive letter?

Windows 批量比较区分大小写的字符串

python - 为什么 Python 对可以嵌套的静态 block 的数量有限制?

python - 如何在运行时在 Python 中从 stub 文件 (.pyi) 获取类型注释?

Java - Windows 中可能的主要方法参数