Read stdout from shell command, was: Becoming root

Michael Hudson mwh21 at cam.ac.uk
Sat Oct 2 05:10:48 EDT 1999


wware-nospam at world.std.com (Will Ware) writes:
> I find I do this quite frequently, usually using something like
> os.popen('some shell command').readline()[:-1] and sure, it works,
> but it's really ugly, and I'm always left with the nagging suspicion
> that since I didn't explicitly close the os.popen(), it might still
> be floating around.

Agree with the ugliness, but don't worry about the dangling pipe:
os.popen() returns a file object and file objects call "close" when
they go out of scope, which this one does pretty rapidly.

Regards,
Michael




More information about the Python-list mailing list