Python subprocess Popen with a seekable pipe?

2019-07-22 05:20发布

问题:

I am calling a binary from Python with subprocess.Popen. I'm passing stdout=subprocess.PIPE so I can pipe the output straight into my Python program and telling the program to send its output to STDOUT rather than a file. It looks like the binary I'm calling wants to be able to seek on the output file. It's not possible to seek on this pipe and I'm getting an error.

I could create a temporary file in Python and tell the binary to write to that, then read it, but that would slow things down quite a lot.

Any suggestions for passing some kind of in-memory buffer to the binary so the program can write and seek, but I can get at it once it is flushed?