[英]Python - how to get the services that run on my computer
I want to create a simple program in python that save all the services that run on my ubuntu linux computer. 我想在python中创建一个简单的程序,保存在我的ubuntu linux计算机上运行的所有服务。 I want it to be as simple as possible when save maximum information about the services. 在保存有关服务的最大信息时,我希望它尽可能简单。 What is the best way to do so? 这样做的最佳方法是什么? Is there a library that I can use? 我有可以使用的图书馆吗?
thanks. 谢谢。
Use this: 用这个:
import subprocess
subprocess.Popen('service --status-all', stdout=subprocess.PIPE).stdout.read()
import subprocess
sp = subprocess.Popen("service --status-all", stdout=subprocess.PIPE).communicate()
print 'Services output: {0}'.format(sp[0])
You could also change the command service --status-all
to any other shell supported command you would like. 您还可以将命令service --status-all
更改为您希望的任何其他shell支持的命令。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.