f = os.popen("gst-launch -q whateversrc ! ... ! fdsink")
f.read(1024);在GNU/Linux上运行良好,但通向\x0d\x0a,而不是Windows的每个\x0a。如何修复?
我也在控制台中尝试了gst-launch -q ..... ! matroskamux streamable=true ! fdsink > qqq3.mkv,qqq3.mkv也乱码了。gst-launch -q filesrc location=file ! fdsink > file2也会转换为CRLF。
该怎么办呢?Gstreamer build for windows没有tcp{server,client}接收器...
也许有一种方法可以在Windows中全局关闭LF->CRLF转换(或者对于给定的应用程序)?
发布于 2012-04-19 09:41:28
我认为也许你不应该在subprocess.Popen()中使用shell=True。
使用64位Windows 7,在Cygwin中运行Python,我编写了以下简单的测试程序:
import subprocess as sp
p = sp.Popen(['cat', 'junk.bin'], stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.
PIPE)
stdin, stdout = p.communicate()
with open('junk1.bin', "wb") as f:
f.write(stdin)对我来说,junk1.bin是junk.bin的完美副本,所以我没有看到发生在您身上的"\n" -> "\r\n"转换。
编辑:我发现了一个看起来很有用的网页:
http://blog.rubypdf.com/2009/11/03/how-to-let-python-send-binary-data-to-stdout-under-windows/
import sys
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)如果子进程继承了父进程的stdin和stdout文件句柄的二进制模式设置,那么在Python父进程中运行上面的代码可能会有所帮助?
如果没有,那么在subprocess.Popen()返回的对象中的stdin和stdout句柄上尝试相同的技巧。在上面代码中,我将对象绑定到名称p,因此它们将分别为p.stdin和p.stdout
msvcrt.setmode(p.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(p.stdout.fileno(), os.O_BINARY)我希望这能帮到你。
https://stackoverflow.com/questions/10219759
复制相似问题