运行终端命令,但不显示通过python的输出

时间:2019-01-10 20:58:39

标签: python linux python-3.x command-line terminal

我尝试过

a = subprocess.run(['apt download timeshhhh'],stdout = subprocess.PIPE, shell = True)

但这显示:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

E: Unable to locate package timeshhhh

我只想要

E: Unable to locate package timeshhhh 

做什么?

1 个答案:

答案 0 :(得分:0)

这是stderr的输出,您没有重定向。如果您不想看到它,可以将其重定向到DEVNULL

a = subprocess.run(['apt download timeshhhh'],stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, shell = True)