1

What do I need do to make sure the data is read as binary and not text when i do

cat binfile | myscript.py

reads as text mode I need binary mode?

data = sys.stdin.read 
moimoi
  • 171
  • 1
  • 7
  • Possible duplicate of [Reading binary data from stdin](https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin) – jez Jan 26 '19 at 19:54

1 Answers1

0

Assuming you're using the latest version of Python, that you're looking for is:

sys.stdin.buffer.read()

Note: You must use help(sys.__stdin__) in interactive mode. This is because you can't use the normal stdin in interactive mode. sys.stdin.buffer simply doesn't exist in interactive mode.

Benoît P
  • 3,179
  • 13
  • 31