On Nov 18, 4:14 pm, Jon Clements <jon...@googlemail.com> wrote: > On Nov 18, 11:25 am, Jean-Michel Pichavant <jeanmic...@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. > > > import subprocess > > commandLine = ['ps', '-eo "%p %U %P %y %t %C %c %a"'] > > process = subprocess.Popen(commandLine, stdout=subprocess.PIPE, > > stderr=subprocess.PIPE) > > processList, stderrdata = process.communicate() > > > Here is a sample of what I get in processList.split('\n'): > > > ' "25487 1122 4344 ? 7-17:48:32 2.5 firefox-bin > > /usr/lib/iceweasel/firefox-"', > > ' "25492 1122 4892 pts/6 00:08 57.2 ipython > > /usr/bin/python /usr/bin/ip"', > > > As you can see, to complete process command line is truncated. > > Any clue on how to get the full version ? > > > JM > > > (python 2.5) > > What about "ps -eo pid,tty,cmd" ? > > Sample: > 12680 ? geany /usr/share/gramps/ReportBase/ > _CommandLineReport.py > 12682 ? gnome-pty-helper > 12683 pts/0 /bin/bash > 13038 ? gnome-terminal > 13039 ? gnome-pty-helper > 13040 pts/1 bash > 13755 pts/1 ps -eo pid,tty,cmd > > ...etc... > > hth, > > Jon.
Another thought: if you're only wanting to find and kill a process, what about pkill? Saves you having to filter the list in Python and then issue a kill command. Jon. -- http://mail.python.org/mailman/listinfo/python-list