Re: getting a process's PID

2006-12-28 Thread Tom Plunket
eldorado wrote: > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] > >>> I understand you're probably set, but instead of using readlines() you could also do this: g = os h

Re: getting a process's PID

2006-12-27 Thread Gabriel Genellina
At Wednesday 27/12/2006 17:33, eldorado wrote: Yes, I was running this on a box that had 1.4 - I just tested it on a box that has 2.3.5 and it runs perfect. Your changes also allow it to be run on the boxes that still have 1.4 Ouch! 1.4 is really really ancient! Even the most conservative li

Re: getting a process's PID

2006-12-27 Thread eldorado
On Wed, 27 Dec 2006, Sebastian 'lunar' Wiesner wrote: > eldorado <[EMAIL PROTECTED]> typed > > Strange!? On my system with Python 2.4 I don't get this error. It is > likely to be a problem of your really ancient python version. Do I > guess correctly from your previous postings, that you're still

Re: getting a process's PID

2006-12-27 Thread Sebastian 'lunar' Wiesner
eldorado <[EMAIL PROTECTED]> typed [snip] > This looks cleaner than the way I was going. I created a file > called ps.py > > #!/usr/local/bin/python > import os > g = os.popen("ps -e -o pid,command") > for line in g.readlines(): > if 'HUB' in line: > pid = line.strip().

Re: getting a process's PID

2006-12-27 Thread eldorado
On Wed, 27 Dec 2006, Sebastian 'lunar' Wiesner wrote: > eldorado <[EMAIL PROTECTED]> typed > >> Hello, >> >> I am trying to get python to give me the PID of a process (in this >> case >> HUB). I have it working, except for the fact that the output includes >> \012 (newline). Is there a way to as

Re: getting a process's PID

2006-12-27 Thread Sebastian 'lunar' Wiesner
eldorado <[EMAIL PROTECTED]> typed > Hello, > > I am trying to get python to give me the PID of a process (in this > case > HUB). I have it working, except for the fact that the output includes > \012 (newline). Is there a way to ask python not to give me a > newline? > > Python 1.4 (Oct 14 19

Re: getting a process's PID

2006-12-27 Thread eldorado
On Wed, 27 Dec 2006, Erik Johnson wrote: > > "eldorado" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > h = g.readlines() > g.close() > h >> ['87334\012'] > h = h[:-1] > h >> [] > > Oh

Re: getting a process's PID

2006-12-27 Thread Erik Johnson
"eldorado" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] Oh, sorry... h is a list here because you are using rea

Re: getting a process's PID

2006-12-27 Thread eldorado
On Wed, 27 Dec 2006, Erik Johnson wrote: > "eldorado" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Hello, >> >> I am trying to get python to give me the PID of a process (in this case >> HUB). I have it working, except for the fact that the output includes >> \012 (newline).

Re: getting a process's PID

2006-12-27 Thread Duncan Booth
"Erik Johnson" wrote: > There's more than one way to do it! (Oh, sorry, that's Perl...) > > The two most standard ways would be to call strip() on your string to > get one sans both leading and trialing whitespace > > print h.strip() > > or if you know exactly what you've got (i.e., the ne

Re: getting a process's PID

2006-12-27 Thread Erik Johnson
"eldorado" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I am trying to get python to give me the PID of a process (in this case > HUB). I have it working, except for the fact that the output includes > \012 (newline). Is there a way to ask python not to give me a newli

getting a process's PID

2006-12-27 Thread eldorado
Hello, I am trying to get python to give me the PID of a process (in this case HUB). I have it working, except for the fact that the output includes \012 (newline). Is there a way to ask python not to give me a newline? Python 1.4 (Oct 14 1997) [C] Copyright 1991-1995 Stichting Mathematisch C