不存储我通常使用非常简单subprocess.check_output
:蟒蛇check_output版画但在VAR
process = subprocess.check_output("ps aux", shell=True)
print process #display the list of process
如果我担心有东西在stderr
,我用它这样的:
process = subprocess.check_output("ps aux 2> /dev/null", shell=True)
print process #display the list of process
但我遇到问题nginx -V
:
modules = subprocess.check_output("nginx -V", shell=True) #display the result
print modules #empty
modules = subprocess.check_output("nginx -V 2> /dev/null", shell=True) #display nothing
print modules #empty
为什么命令nginx -V
行为不同(所有打印在stderr
)?我如何设计esealy与``subprocess.check_output`解决方法?
这可能是流程具体打印到它运行,而不是正常渠道的终端。 – languitar