moshem
moshem

Reputation: 99

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. 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.

Upvotes: 1

Views: 90

Answers (2)

Maorg
Maorg

Reputation: 83

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.

Hope this helps.

Upvotes: 1

j4hangir
j4hangir

Reputation: 3069

Use this:

import subprocess
subprocess.Popen('service --status-all', stdout=subprocess.PIPE).stdout.read()

Upvotes: 2

Related Questions