在哪里可以找到所有 subprocess.call() 代码 (0,1,2 ..)?

Where can I find all the subprocess.call() codes (0,1,2 ..)?

我是运行下面的Python代码,查了subprocess的文档还是没有找到代码图:

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
call("sudo pip3 install --upgrade " + ' '.join(packages), shell=True)

输出:2

2 是什么意思?有时它是 0 或 1。

shell 脚本或用户执行的每个 Linux 命令都有一个退出状态。

Linux 手册页统计了每个命令的退出状态。

  • 0 退出状态表示命令成功,没有任何错误。
  • 非零(1-255 个值)退出状态表示命令失败。

典型的信号是:

0 – Success.

1 – A built-in command failure.

2 – A syntax error has occurred.

3 – Signal received that is not trapped.

某些退出状态值已保留用于特殊用途:

126 - A file to be executed was found, but it was not an executable utility.

127 - A utility to be executed was not found.

128 - A command was interrupted by a signal.

负值 -N 表示子进程被信号 N 终止(仅 POSIX)。

代码是特定于平台的,例如 Windows:

0 - Success

1 - Invalid function

2 - File not found

3 - Path not found

4 - Too many open files

etc...

来自python doc:

Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors.