简体   繁体   English

python popen不打印标准输出

[英]python popen doesnt print stdout

i am trying to run a command racadam from dell(its a command line tool), into a subprocess.popen. 我试图从Dell(它的命令行工具)运行命令racadam到subprocess.popen中。

but I cant get back the stdout, or the stderr. 但是我无法找回标准输出或标准错误。 this is what I am doing. 这就是我在做什么。

prog = "C:\Program Files\Dell\SysMgt\\rac5\\racadm.exe"
pp = subprocess.Popen(prog, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
pp.communicate()
print pp.communicate()

print pp.communicate()[0]
print pp.communicate()[1]

print pp.stdout.readlines()
print pp.stderr.readlines()

out, err = pp.communicate()
print out
print err

and I just get 我得到

('', '')


[]
[]

when it should be printing the help with what arguments do what. 什么时候应该打印带有哪些参数的帮助。

the funny thing is I can see that program terminal opening, printing some lines and then close super super fast. 有趣的是,我可以看到程序终端打开,打印了一些行,然后超级快速地关闭了。 so I know that the program is running I just cant get the information back to python =( may I bee missing some steps? or is there a hidden trick? 所以我知道程序正在运行,我只是无法将信息返回给python =(我可能会错过一些步骤吗?还是有隐藏的技巧?

thanks guys. 多谢你们。

Not sure if you have actually written tdout instead of stdout while running your code 不确定在运行代码时是否实际写了tdout而不是stdout

Try this 尝试这个

pp = subprocess.Popen(prog, shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = pp.communicate()
if pp.returncode == 0:
   final = out
else:
   final = err

print "Final output/Error is "+final

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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