George V. Reilly

Python Batchfile Wrapper

I've been getting into Python lately. One problem that I've en­coun­tered under Windows, is that input redi­rec­tion doesn't work if you use the .py file as­so­ci­a­tion to run the script; e.g.:

C:\> foo.py < input.txt

There's a well-known input redi­rec­tion bug. The fix is to explicitly use python.exe to run the script.

A related problem for me was that stdin was opened as a text file, not a binary file, so \r bytes were being discarded from binary input files. The fix is to run python.exe -u (unbuffered binary input and output).

I didn't want to hardcode the path to python.exe in a batch file, so I came up with the continue.

« Next