Beginner asks question about Python on Linux

stephen.allison at cenes.co.uk stephen.allison at cenes.co.uk
Fri Oct 8 06:18:52 EDT 1999


Hello all,

I have a, probably fairly trivial, question about using Python on Linux
(and probably Unix too).  I'm quite new to both, so apologies if it's a
really stupid question.

I'm writing some scripts to do some general administation tasks, and
need to get the output of a shell command into Python easily.  For
example I have a bit of code like this:

os.system("ps aux|grep someProcess > pids.temp")

I then proceed to open the pids.temp file, read the lines and then go
on to do stuff with the processes (readline, splitfields, look through
the list for the PIDs, execute further system commands (usually
'kill')), and then delete the pids.temp file.  What I want to know is
if there is a way of getting the output of the grep straight into
Python, so I won't have to use a temporary file.  I have since learned
about killing all processes of a given name, so it's a bit academic,
but I was wondering if anyone could tell me if it's possible to do
this, using either Python cleverness or some shell commands I'm not
aware of.

Thanks for any help,

Steve


--
Steve Allison
Doesn't read deja news mail


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list