简体   繁体   中英

What is the use of stderr=subprocess.STDOUT in subprocess.check_output()?

I am writing a code in Python that is supposed to run some commands. To do this I'm using subprocess.check_output() as it allows to have a timeout. I understand how it works and what parameters we are supposed to give to it however I saw online that people are using "stderr=subprocess.STDOUT" a lot and I was wondering what it does and if I should use it or not.

I'm using Python 3.7

Here is an example of code:

import subprocess as sp

out = sp.check_output("ls not_existing_folder", 
                      stderr=sp.STDOUT, 
                      universal_newlines=True, 
                      timeout=15)

So I tried running it with and without the "stderr=sp.STDOUT" line but it doesn't appear to change anything. I saw online that it's supposed to catch the error message, preventing a display in the console. I'm not sure I got that right... Can someone explain me the use of this piece of code?

它不是像往常一样将其报告为错误,而是将其作为标准输出打印到控制台。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM