subprocess.check_output():显示失败时的输出 [英] subprocess.check_output(): show output on failure

查看:44
本文介绍了subprocess.check_output():显示失败时的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

subprocess.check_output() 的输出现在看起来像这样:

The output of subprocess.check_output() looks like this at the moment:

CalledProcessError: Command '['foo', ...]' returned non-zero exit status 1

有没有办法获得更好的错误信息?

Is there a way to get a better error message?

我想看看stdoutstderr.

推荐答案

由于不想写更多的代码,只是为了得到一个好的错误提示,我写了subx

Since I don't want to write more code, just to get a good error message, I wrote subx

来自文档:

subprocess.check_output() vs subx.call()

subprocess.check_output() vs subx.call()

查看、比较、思考并决定哪些信息对您更有帮助.

Look, compare, think and decide what message helps your more.

subprocess.check_output()::

subprocess.check_output()::

CalledProcessError: Command '['cat', 'some-file']' returned non-zero exit status 1

sub.call()::

sub.call()::

SubprocessError: Command '['cat', 'some-file']' returned non-zero exit status 1:
stdout='' stderr='cat: some-file: No such file or directory'

... 特别是如果代码在生产环境中失败时重现错误并不容易,subx 可以打电话帮你发现失败的根源.

... especially if the code fails in a production environment where reproducing the error is not easy, subx can call help you to spot the source of the failure.

这篇关于subprocess.check_output():显示失败时的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆