I have a number of executables that I'm running using a python script. The programs all print to an output file using fprintf, as well as writing to the console. Is there a way to intercept the output when they write to the file?
Whether I use Popen or check_output, the programs don't create the file, but the values that they write to the file don't show up in stdout. The output seems to simply disappear, and I only get the data that they write to the console.
It seems like either no one else has this issue, or no one ever needs to capture file output from a subprocess and I'm going a little crazy trying to figure it out.
If it helps, this is the code i'm using to call each exe. x is the file path and qx is what I've imported check_output as.
try:
output = qx(x, stderr=STDOUT)
outputFile.write('\t\t' + output + '\n')
except CalledProcessError as ex:
outputFile.write('\t\t' + str(ex.output) + '\n')
outputFile.write('\t Program exited with code: ' + str(ex.returncode) + '\n')
Edit: Eheh actually it turns out that the output file isn't simply disappearing into the cold void after all. My bad. Still, is there a way to capture file output from a subprocess?