I'm trying to pipe a io.BytesIO() bytetream to a separate program using subprocess.popen(), but I don't know how or if this is at all possible. Documentation and examples are all about text and newlines.
When I whip up something like this:
import io
from subprocess import *
stream = io.BytesIO()
someStreamCreatingProcess(stream)
command = ['somecommand', 'some', 'arguments']
process = Popen(command, stdin=PIPE)
process.communicate(input=stream)
I get
Traceback (most recent call last):
File "./test.py", line 9, in <module>
procOut = process.communicate(input=stream)
File "/usr/lib/python2.7/subprocess.py", line 754, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1322, in _communicate
stdout, stderr = self._communicate_with_poll(input)
File "/usr/lib/python2.7/subprocess.py", line 1384, in _communicate_with_poll
chunk = input[input_offset : input_offset + _PIPE_BUF]
TypeError: '_io.BytesIO' object has no attribute '__getitem__'
I think popen() is only for text. Am I wrong?
Is there a different way to do this?