在Python2.x中,os.popen(command, "b")为我提供了给定命令输出的二进制流。这在Windows上非常重要,因为在Windows中,二进制流和文本流实际上提供了不同的字节。
subprocess模块应该取代os.popen和其他子进程衍生API。然而,转换文档根本没有讨论处理"b“模式。如何使用subprocess获取二进制输出流
发布于 2010-08-12 11:47:41
默认情况下,它是这样做的,除非您正在执行Popen(..., universal_newlines=True)。
class Popen(object):
[...]
def __init__(self, ...):
[...]
if p2cwrite is not None:
self.stdin = os.fdopen(p2cwrite, 'wb', bufsize)
if c2pread is not None:
if universal_newlines:
self.stdout = os.fdopen(c2pread, 'rU', bufsize)
else:
self.stdout = os.fdopen(c2pread, 'rb', bufsize)
if errread is not None:
if universal_newlines:
self.stderr = os.fdopen(errread, 'rU', bufsize)
else:
self.stderr = os.fdopen(errread, 'rb', bufsize)https://stackoverflow.com/questions/3464589
复制相似问题