簡體   English   中英

Python - 如何獲取在我的計算機上運行的服務

[英]Python - how to get the services that run on my computer

我想在python中創建一個簡單的程序,保存在我的ubuntu linux計算機上運行的所有服務。 在保存有關服務的最大信息時,我希望它盡可能簡單。 這樣做的最佳方法是什么? 我有可以使用的圖書館嗎?

謝謝。

用這個:

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])

您還可以將命令service --status-all更改為您希望的任何其他shell支持的命令。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM