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

标签 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 

怎么办?

最佳答案

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

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

关于python - 运行终端命令但不通过 python 显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54136784/

相关文章:

python - 谁能给我解释一下 "guardian pattern"

python - 如何在 Pygame 中获取 Sprite 的位置?

linux - 将 tar 存档命名为与源文件相同

python - 将 numpy 数组的负值变为正值

python - 错误的 UDP 校验和无效 : why?

python - Pandas read_csv() 适用于 Python 3 中的 CSV 文件,但在 Python 2 中返回 NaN

python - 使用python在HDFS中创建文件

linux - apt-get install 只显示最后一行

linux - SO_REUSEADDR 导致服务器重用 TIME_WAIT 连接?

html - 提高 BeautifulSoup 解析速度