raw stdin/out on WIN32?

Yann SAMAMA ysamama at cybercable.fr
Wed Mar 15 17:47:59 EST 2000


Hi all!!
>
>piping binary data isn't a very common thing to do
>under windows. maybe you should consider using
>an ordinary argument instead, so you can control
>how the files are opened?


I have also set an [-f file] option...

>> Any clue really welcomed!
>
>here's one:
>
>usage: python [option] ... [-c cmd | file | -] [arg] ...
>Options and arguments (and corresponding environment variables):
>...
>-u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)
>...
>
></F>


Finally I've found the solution to redefine the way stdin/out/err are opened
on WIN32.

****code begins here****
import sys
if sys.platform == "win32":
    import msvcrt
    msvcrt.setmode(0, os.0_BINARY) # 0 = stdin, 1 = stdout, 2 = stderr, you
can also use sys.stdin/out/err.fileno()
****code ends here****

The most interesting thing is that this code raises an exception under
PythonWin, and works perfectly when run from the shell (command.com)?

My father would say : sometimes, don't try to understand, just thank God....

Hope this helps...

Yann





More information about the Python-list mailing list