os.getlogin() raises OSError (errno 25)

David Carson davidccarson at hotmail.com
Tue Jul 23 23:46:17 EDT 2002


Could someone please explain why the following runs fine if I type the
input and end stdin with ctrl-D, but bombs when I pipe stdin to it.

=== eg.py ===
#!/usr/bin/env python

import os, sys

tag = sys.stdin.read().strip()
loginName = os.getlogin()
print loginName, tag
=== end ===

Run without pipe, typing input and ctrl-D, looks like:
> eg.py
hello
^D
dcarson hello
>
>


Run by piping my input to the script, I get:
> echo hello | eg.py 
Traceback (most recent call last):
  File "./eg.py", line 7, in ?
    loginName = os.getlogin()
OSError: [Errno 25] Inappropriate ioctl for device
>
>

Environment:
python 2.2
mandrake Linux 8.2

Thanks in advance,
David



More information about the Python-list mailing list