I don't think I understand popen2() behaviour
Timothy Grant
tjg at exceptionalminds.com
Mon Feb 12 13:03:37 EST 2001
Hi,
I need some enlightenment. For the first time ever, I'm playing with pipes
in python and I must be missing something. I'll paste in a couple of
examples to see if I can explain myself.
>>> import os
>>> x = os.popen('tail -f /var/log/messages')
>>> tail: /var/log/messages: Permission denied
tail: no files remaining
>>>
OK, so I'd expect that behaviour, as I'm logged in as me, not root.
Now, my understanding of popen2() is that it gives me a file handle to both
stdin and stderr, so since I don't want those error messages popping up on
the screen I tried the following
>>> import popen2
>>> x,y = popen2.popen2('tail -f /var/log/messages')
>>> tail: /var/log/messages: Permission denied
tail: no files remaining
>>>
Now that was unexpected, as I would have thought that the error messages
should have been hidden away in my file object y, and that I wouldn't see
them until I did a y.readlines() or something. However, when I try to access
y, I get the following:
>>> y.readlines()
Traceback (innermost last):
File "<stdin>", line 1, in ?
IOError: [Errno 9] Bad file descriptor
>>>
So, obviously I don't understand something, but I'm not even sure what it is
I don't understand yet!
Thanks for your assistance.
--
Stand Fast,
tjg.
Timothy Grant tjg at exceptionalminds.com
Red Hat Certified Engineer www.exceptionalminds.com
Avalon Technology Group, Inc. (503) 246-3630
>>>>>>>>>>>>>Linux, because rebooting is *NOT* normal<<<<<<<<<
>>>>This machine was last rebooted: 26 days 22:08 hours ago<<
More information about the Python-list
mailing list