getting properly one subprocess output

Bas wegwerp at gmail.com
Thu Nov 19 09:21:09 EST 2009


On Nov 18, 12:25 pm, Jean-Michel Pichavant <jeanmic... at sequans.com>
wrote:
> Hi python fellows,
>
> I'm currently inspecting my Linux process list, trying to parse it in
> order to get one particular process (and kill it).
> I ran into an annoying issue:
> The stdout display is somehow truncated (maybe a terminal length issue,
> I don't know), breaking my parsing.

Below is the script I use to automatically kill firefox if it is not
behaving, maybe you are looking for something similar.

HTH,
Bas


#!/usr/bin/env python

import commands, os
lines = os.popen('ps ax|grep firefox').readlines()
lines = [line for line in lines if 'grep' not in line]
print lines[0]
pid = int(lines[0][:5])
print 'Found pid: %d' %pid
os.system('kill -9 %d' %pid)



More information about the Python-list mailing list