stdin, stdout, redmon

Tim Golden mail at timgolden.me.uk
Tue Jan 22 04:58:33 EST 2008


Bernard Desnoues wrote:
> Hello,
> 
> I checked under linux and it works :
> text.txt :
> "first line of the text file
> second line of the text file"
> 
> test.py :
> "import sys
> a = sys.stdin.readlines()
> x = ''.join(a)
> x = x.upper()
> sys.stdout.write(x)"
> 
>  >cat text.txt | python test.py
> 
> But I reinstalled Python 2.5 under Windows XP and it doesn't work 
> anyway. Can you confirm that your script works with Win XP and Python 2.5 ?

How are you invoking the script under WinXP? If you're
using the standard file associations then stdin/stdout
won't work correctly. However, they produce a specific
error message:

<dump>
C:\temp>type test3.py
import sys

print sys.stdin.readlines ()
C:\temp>
C:\temp>type test3.py | test3.py
Traceback (most recent call last):
   File "C:\temp\test3.py", line 3, in <module>
     print sys.stdin.readlines ()
IOError: [Errno 9] Bad file descriptor

C:\temp>type test3.py | python test3.py
['import sys\n', '\n', 'print sys.stdin.readlines ()']

</dump>

TJG



More information about the Python-list mailing list