Topic: Reading subprocess output as a File
Hi everyone, I can't find a solution to (what seems to be) a simple problem.
The output of a program is a ppm image file. I tell the program to write the ppm to stdout. I redirect the stdout to a variable in Python with the subprocess module. Everything here is fine.
But then I want to handle it via another library (called netpbm)
The problem is, the library takes input as filename, but it is the exactly same thing in the variable. So isn't there a way to point the variable as a file???
Maybe an example would be better :
import subprocess, netpbm
# the "-c" tells dcraw to write to stdout, NOT to file.ppm
p = subprocess.Popen(["dcraw","-c","file.cr2"],stdout=subprocess.PIPE).communicate()[0]
# Here in the varible p we have the file.
# Normally, "$ dcraw -c file.cr2" will printout the bytes of the ppm file.
# Now i want to open it ("p") like a regular file.
p_arr = netpbm.asarray(p)
# This last line of course doesn't work, cuz the argument passed to .asarray has to be a file!Please don't say that it has anything to do with the netpbm library I'm using. My problem is, I want the "p" variable to act as a file somehow, for any other function too, of course without writing it to an actual file.
Hope I made myself clear.