简体   繁体   English

Python - 如何获取在我的计算机上运行的服务

[英]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.

相关问题 如何使Python程序在任何计算机上运行? - How to get Python program to run on any computer? 如何在计算机上的python2和3上运行PySpark / spark? - How do I get PySpark/spark to run on both python2 and 3 on my computer? 如何使 django rest api 在我的计算机中运行 python 文件 - How to make a django rest api run a python file in my computer 如何在计算机关闭的情况下在后台运行python的spark应用程序? - How can I run my spark app with python in the background with my computer shut off? 如何通过Python在计算机终端中运行命令 - How to Run a Command in the Computer Terminal Through Python 每次我的计算机从睡眠中醒来时如何运行 python 脚本? - How to run a python script every time my computer wakes up from sleep? 如何在Python中获取计算机的完全限定域名? - How do I get my computer's fully qualified domain name in Python? 如何在没有 python 的计算机上使用第三方库运行 python 脚本? - How to run python script with third party libraries on computer without python? 如何在计算机关闭时运行 cmd 脚本? - How can I run a cmd script while my computer is off? 如何创建我自己的 Python package 并将其保存在我的电脑上 - How to create my own Python package and save it on my computer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM