I have a command line utility (exiftool) which accepts input via stdin.
Calling it from python might look like this:
ps = Popen(['exiftool','-groupNames','-json', '-'], stdin=PIPE, stdout=PIPE)
Where the pipe is used via:
with open(ffile, 'r') as fh:
ps.stdin.write(fh.read())
ps.stdin.close()
print ps.stdout.read()
ps.wait()
As expected, this outputs the result of running exiftool with the contents of ffile
passed as an argument.
I can call this code repeatedly in a loop, but it results in a fork
for every call and is actually slow (this is not a case of premature optimization).
So I'm wondering if there is a way to open exiftool once, and then "re-use" Popen, piping multiple files in to it, and saving the output for each one.
It doesn't seem like it is possible, because exiftool (unlike cat) seems to interpret its input as an entire chunk, instead of line by line or according to some delimiter. But perhaps it is possible by hacking the exiftool process's stdin?