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, sorry... h is a list here because you are using readlines().
> I am used to doing this:
>
> fd = os.popen('ps -ef | grep python')
> s = fd.read()
>
> to get a single string. You can do something like
>
> s = h[0]
>
> and then operate on s, or you can use read() in place of readlines() to get
> h as a single string, or you can operate on the first element of h:
>
>>>> h = ['87334\012']
>>>> h[0][:-1]
> '87334'
>>>> h[0].rstrip('\n')
> '87334'
>
> All the error handling to do in the case where you actually have multiple
> processes being matched is up to you. ;)

Erik,
Thank you very much.  Works perfect. I am now off to work on the multiple 
process issue.


  -- 
Randomly generated signature
Claiming that your operating system is the best in the world because more 
people use it is like saying McDonalds makes the best food in the world.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to