我正在尝试使用subprocess.popen ()将 io.BytesIO() 字节流通过管道传输到单独的程序,但我不知道如何或是否有可能。文档和示例都是关于文本和换行符的。
当我掀起这样的事情时:
import io
from subprocess import *
stream = io.BytesIO()
someStreamCreatingProcess(stream)
command = ['somecommand', 'some', 'arguments']
process = Popen(command, stdin=PIPE)
process.communicate(input=stream)
我明白了
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__'
我认为popen()仅适用于文本。我错了吗?
有不同的方法可以做到这一点吗?