开发者

How to use subprocess to invoke "/etc/init.d/tomcat6/ stop" in Python

I want to invoke /etc/init.d/tomcat6 in subprocess. I have tried the below code, but it didn't work.

cmd="/etc/init.d/tomcat6/ stop"
p=subprocess.Popen(cmd)
stdout, stderr = p.communicate()
print s开发者_开发问答tdout,stderr

Anyone could help me, thanks.


Do it this way:

subprocess.call(['/etc/init.d/tomcat6', 'stop'])

or, if you really need to capture the standard output/error

p = subprocess.Popen(['/etc/init.d/tomcat6', 'stop'],
                     stdout=subprocess.PIPE,
                     stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜