In an attempt to create a simple cat
clone in python,
sys.stdout.write(sys.stdin.read())
I noticed that this fails horribly for binary files (i.e. python cat.py < binaryfile > supposed_copy
) containing the CTRL+Z EOF / substitude character 0x1a, since that seems to cause read()
to consider its work done. I cannot simply loop over the code forever to circumvent this, since obviously at some point stdin.read()
will wait until new input is provided, which once the true end of input is reached won't ever happen.
So, how can this be fixed, i.e.
- How to know when the file redirected to
stdin
is fully read, or - how to properly handle this?