[Tutor] commands module

DS ds-python-tutor at sidorof.com
Fri Dec 7 00:05:44 CET 2007

I've been trying to do something that I thought was going to be
relatively straight-forward, but so far I haven't found a good solution.

What I'm trying to do is discover a pid on a process and kill it.  The
way that I thought that I could do it is something along the lines of:

import commands

program = "someprogram"

a = commands.getoutput('ps ax|grep %s ' % (program))

Then, I'd parse the returned info get the pid and kill it, probably via
another command.

However, what happens is that the "ps ax" portion truncates the listing
at 158 characters.  It just so happens that the unique name that I need
in the list comes after that.  So, works from the bash shell, but
doesn't work using getoutput.

I have also tried variations on a theme.  For example, I created a shell
file and tried to route into a file:
ps ax|grep my_program_name > ps.output

No luck.

Do you have any suggestions?

More information about the Tutor mailing list