python - 如何将终端错误传递给 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 程序,并在终端显示这样的错误时运行该程序。
我怎样才能传递错误?
解决方案
推荐阅读
- html - 停止父级滚动并允许绝对定位的子级与父级重叠
- wpf - 在 WPF 中,是否可以将属性的绑定设置为绑定依赖属性?
- python - 在 Django 站点的 pex 上调用 runserver 时如何解决 NotADirectoryError?
- python - 如何使用 python-pptx 删除 pptx 表中不需要的行空间?
- javascript - 将函数分配给变量与仅调用函数相比有什么好处?
- python-3.x - Python3:断言'iter_is_valid(iter,list_store)'失败
- python - Flask-SQLAlchemy & Google App Engine - 没有写权限
- r - # R 子集只有一个或两个字符分别在模式之前?
- javascript - 弹出编辑表格内容
- rpa - 如何使用 UIPath 中的关闭选项卡活动关闭子选项卡