views:

5

answers:

1

i want to invoke /etc/init.d/tomcat6 in subporcess i have tried bellow code,but it didn't work

cmd="/etc/init.d/tomcat6/ stop"
p=subprocess.Popen(cmd)
stdout, stderr = p.communicate()
print stdout,stderr

anyone could help me,thanks

A: 

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()
Marius Gedminas