Reading binary data from stdin
<p>Is it possible to read stdin as binary data in Python 2.6?  If so, how?</p>

<p>I see in the <a href="http://docs.python.org/py3k/library/sys.html" rel="nofollow">Python 3.1 documentation</a> that this is fairly simple, but the facilities for doing this in 2.6 don't seem to be there.</p>

<p>If the methods described in 3.1 aren't available, is there a way to close stdin and reopen in in binary mode?</p>

<p><strong>Update</strong></p>

<p>Just to be clear, I am using 'type' in a MS-DOS shell to pipe the contents of a binary file to my python code.  This should be the equivalent of a Unix 'cat' command, as far as I understand.  But when I test this out, I always get one byte less than the expected file size.</p>

<p><strong>Update #2</strong></p>

<p>First off, thanks for all the answers.  I'm slowly working towards a real, usable solution here.  In the end, I'm still trying to build a self contained JAR file that executes my Python code automatically passing through all the command line arguments untainted.  </p>

<p>The reason I'm going the Java/JAR/Jython route is because one of my main external libraries is only available as a Java JAR.  But unfortunately, I had started my work as Python.  It might have been easier to convert my code over to Java a while ago, but since this stuff was all supposed to be compatible, I figured I would try trucking through it and prove it could be done.</p>

<p>In case anyone was wondering, this is also related to the question I asked a few days ago.</p>

<p><a href="http://stackoverflow.com/questions/2827771/packaging-and-deploying-a-jython-program-from-eclipse">http://stackoverflow.com/questions/2827771/packaging-and-deploying-a-jython-program-from-eclipse</a></p>

<p>Some of that question was answered in this <a href="http://stackoverflow.com/questions/1252965/distributing-my-python-scripts-as-jars-with-jython">question</a>.</p>

<p>So I'll try to update my original question with some notes on what I have figured out so far.</p>
