Problem redirecting stdin on Windows

A

aurora

On Windows (XP) with win32 extension installed, a Python script can be
launched from the command line directly since the .py extension is
associated with python. However it fails if the stdin is piped or
redirected.

Assume there is an echo.py that read from stdin and echo the input.



Launching from command line directly, this echos input from keyboard:

echo.py



But it causes an error if the stdin is redirected

echo.py <textfile


...
for line in fp:
IOError: [Errno 9] Bad file descriptor



However it works as expected if launched via Python.exe

c:\Python24\python.exe echo.py <textfile



Why is the second option fails? It makes many script lot less functional.
 
V

vincent wehren

| On Windows (XP) with win32 extension installed, a Python script can be
| launched from the command line directly since the .py extension is
| associated with python. However it fails if the stdin is piped or
| redirected.
|
| Assume there is an echo.py that read from stdin and echo the input.
|
|
|
| Launching from command line directly, this echos input from keyboard:
|
| echo.py
|
|
|
| But it causes an error if the stdin is redirected
|
| echo.py <textfile
|
|
| ...
| for line in fp:
| IOError: [Errno 9] Bad file descriptor
|
|
|
| However it works as expected if launched via Python.exe
|
| c:\Python24\python.exe echo.py <textfile
|
|
|
| Why is the second option fails? It makes many script lot less functional.

See:
http://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top