首页 > 解决方案 > 如何将终端错误传递给 Python 脚本?

问题描述

每当在终端中触发错误时,如何将终端错误传递给 Python 程序?

例子:

考虑我正在运行一个 java 程序,我得到一些像这样的错误

file.java:2: error: ',', ')', or '[' expected
    public static void main(String args...) {
                                       ^
1 error

另一个例子是输入错误的 bash 命令

ls: option '--a' is ambiguous; possibilities: '--all' '--almost-all' '--author'
Try 'ls --help' for more information.

我需要将此错误传递给 python 程序,并在终端显示这样的错误时运行该程序。

我怎样才能传递错误?

标签: python

解决方案


推荐阅读