Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行终端命令,但不要';无法通过python显示输出_Python_Linux_Python 3.x_Command Line_Terminal - Fatal编程技术网

运行终端命令,但不要';无法通过python显示输出

运行终端命令,但不要';无法通过python显示输出,python,linux,python-3.x,command-line,terminal,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 tim

我试过这个

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 
我只想要:

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)

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

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

在换行符上拆分并捕获最后一项。问题的标题与文本不匹配。“不通过python显示输出”与只想看到最后一行不同。在换行符上拆分并捕获最后一项。问题的标题与文本不匹配。“不通过python显示输出”与只想看到最后一行不同。不是100%的
警告
输出将在
stderr
上。如果它不是来自管道,则可能是。不是100%的
警告
输出将在
stderr
上。如果它不是来自管道,则可能是。