os.popen and place in file

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Wed Jun 5 12:06:58 EDT 2002


On Wed, 05 Jun 2002 09:59:46 -0500, Stephen Boulet
<stephen.boulet at motorola.com> wrote:
> I'm running windows NT.

    My condolences. :)

> returns a file object 'f'. I can't however use the seek command on it:

    I can't do this on Linux either. 

>>> import os
>>> pipe = os.popen('ls /bin', "r")
>>> pipe.readlines()
['ae\n', 'arch\n', 'bash\n', 'bsd-csh\n', 'cat\n', 'chgrp\n', 'chmod\n',
'chown\n', 'cp\n', 'cpio\n', 'csh\n', 'date\n', 'dd\n', 'df\n', 'dir\n',
'dmesg\n', 'dnsdomainname\n', 'domainname\n', 'echo\n', 'ed\n', 'egrep\n',
'elvis-tiny\n', 'env\n', 'false\n', 'fdflush\n', 'fgrep\n', 'fuser\n',
'grep\n', 'gunzip\n', 'gzexe\n', 'gzip\n', 'hostname\n', 'kill\n', 'ksh\n',
'ln\n', 'loadkeys\n', 'login\n', 'ls\n', 'lspci\n', 'mkdir\n', 'mknod\n',
'mktemp\n', 'more\n', 'mount\n', 'mt\n', 'mt-gnu\n', 'mv\n', 'netstat\n',
'nisdomainname\n', 'pidof\n', 'ping\n', 'ps\n', 'pwd\n', 'rbash\n',
'readlink\n', 'rm\n', 'rmdir\n', 'run-parts\n', 'sed\n', 'setserial\n',
'sh\n', 'sleep\n', 'stty\n', 'su\n', 'sync\n', 'tar\n', 'tcsh\n',
'tempfile\n', 'touch\n', 'true\n', 'umount\n', 'uname\n', 'uncompress\n',
'vdir\n', 'vi\n', 'ypdomainname\n', 'zcat\n', 'zcmp\n', 'zdiff\n', 'zegrep\n',
'zfgrep\n', 'zforce\n', 'zgrep\n', 'zless\n', 'zmore\n', 'znew\n']
>>> pipe.seek(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 29] Illegal seek

    Since the "file" in this case is a temporary buffer used by the pipe
implementation, it probably purges as you read, preventing any seeking.
Remember, it's not a real file. 

    Mike

-- 
Michael P. Soulier, QX41, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix



More information about the Python-list mailing list