Linked Questions
16 questions linked to/from Reading binary data from stdin
59
votes
1
answer
49k
views
Read stdin as binary [duplicate]
I have code that opens and reads a file from binary.
with open (file, mode="rb") as myfile:
message_string=myfile.read()
myfile.close
I now need to do the same thing reading from stdin. But ...
5
votes
3
answers
6k
views
How to prevent "UnicodeDecodeError" when reading piped input from sys.stdin? [duplicate]
I am reading some mainly HEX input into a Python3 script. However, the system
is set to use UTF-8 and when piping from Bash shell into the script, I keep
getting the following UnicodeDecodeError ...
61
votes
4
answers
60k
views
Distributing my Python scripts as JAR files with Jython?
I have been a Python programmer for almost two years, and I am used to writing small scripts to automate some repetitive tasks I had to do at the office. Now, apparently my colleagues noticed this, ...
5
votes
3
answers
8k
views
Python and 16-bit PGM
I have 16-bit PGM images that I am trying to read in Python. It seems (?) like PIL does not support this format?
import Image
im = Image.open('test.pgm')
im.show()
Shows roughly the image, but it isn'...
3
votes
2
answers
4k
views
Packaging and deploying a Jython program from Eclipse
So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. ...
2
votes
1
answer
2k
views
read files with different encoding format using sys.stdin in python3
I have many files which are encoded with UTF-8 or GBK. My system encoding is UTF-8 (LANG=zh_CN.UTF-8), so I can read files encoded with UTF-8 easily. But I must read file encoding with GBK as well. I'...
1
vote
1
answer
2k
views
Python 2.7 - How to programmatically read binary data from stdin
I'd like to be able to read binary data from stdin with python.
However, when I use input = sys.stdin.buffer.read(), I get the error that AttributeError: 'file' object has no attribute 'buffer'. ...
2
votes
3
answers
467
views
How to know when stdin is empty if it contains EOF?
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) ...
0
votes
1
answer
1k
views
How can I get readlines() to ignore the EOF 0x1A character?
I am writing a Python script that will take STDIN from TextWrangler and do something to it on a line by line basis. In Textwrangler, I combine multiple text files using drag and drop. Problem is ...
1
vote
3
answers
1k
views
Loading a defaultdict in Hadoop using pickle and sys.stdin
I posted a similar question about an hour ago, but have since deleted it after realising I was asking the wrong question. I have the following pickled defaultdict:
ccollections
defaultdict
p0
(...
1
vote
1
answer
1k
views
How to read binary data via pipe in python
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
2
votes
3
answers
521
views
Python: piping pcap file to stdout gives error
I am trying to pipe the output of xz to a custom python script:
xz -cd file.pcap.xz | myscripy.py
However, I get an error when the script attempts to run this line:
#!/usr/bin/env python2.7
from ...
1
vote
0
answers
1k
views
Python3 Tarfile: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position
I am trying to port a piece of python2 code to python3. The code works perfectly in python2, but fails in python3. In the original python2 code, data is being compressed into a tarfile as follows:
...
3
votes
0
answers
415
views
Python 2.7 - How to preserve binary data read from stdin
I'd like to be able to read binary data from stdin and have it preserved as binary data (i.e. no coercion to string as sys.stdin.read does). How can I do this with Python 2.7?
Edit: The answers ...
2
votes
1
answer
312
views
Python: Reading and Writing to a binary file in Powershell from stdin
I have the following two programs written in Python
# cat.py
import sys
filename = sys.argv[1]
with open(filename, "rb") as f:
while c := f.read(1024 * 1024):
sys.stdout.buffer....