运行终端命令,但不要';无法通过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
上。如果它不是来自管道,则可能是。