如何使用子进程调用“/etc/init.d/tomcat6/stop”在Python中

发布于 2024-09-27 10:37:15 字数 215 浏览 0 评论 0原文

我想在子进程中调用 /etc/init.d/tomcat6 。 我已经尝试过下面的代码,但它不起作用。

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

任何人都可以帮助我,谢谢。

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 stdout,stderr

Anyone could help me, thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-10-04 10:37:15

这样做:

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

或者,如果您确实需要捕获标准输出/错误

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文