【发布时间】:2012-12-24 16:15:43
【问题描述】:
所以我试图将命令的输出存储到变量中。我不希望它在运行命令时显示输出...
我现在的代码如下...
def getoutput(*args):
myargs=args
listargs=[l.split(' ',1) for l in myargs]
import subprocess
output=subprocess.Popen(listargs[0], shell=False ,stdout=subprocess.PIPE)
out, error = output.communicate()
return(out,error)
def main():
a,b=getoutput("httpd -S")
if __name__ == '__main__':
main()
如果我把它放在一个文件中并在命令行上执行它。即使代码中没有打印语句,我也会得到以下输出。如何在存储输出的同时防止这种情况发生?
#python ./apache.py
httpd: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xx for ServerName
Syntax OK
【问题讨论】:
标签: python subprocess