I have an executable I need to run via a python script and the executable takes a path to a file as an argument, like so:
./myExecutable /pathToFileToProcess
I'm hoping I can run my executable with Popen and pass a string representing my "/pathToFileToProcess" data without having to write it to disk.
I believe what I'm trying to do is very similar to the question asked here: Python string as file argument to subprocess
However the solution suggested isn't working for me. Here is how I've tried to implement it:
from subprocess import Popen, STDOUT, PIPE
stringDataFromFile = "the data to be processed"
p = Popen(['./myExecutable'], shell = False, stdout = PIPE, stderr = PIPE, stdin = PIPE)
stdout, stderr = p.communicate(input = stringDataFromFile)
print(stdout)
print(stderr)
When I run this I get the generic usage message for ./myExecutable in stdout which is what happens if you don't supply a file to process. Note: I need to capture the stdout so I have implemented it slightly differently than the suggested.
I'm thinking the difference must be that ./myExecutable won't accept it's input via stdin, where as the program in the linked example will. Or, I'm just doing it wrong.
Any thoughts on how to do this, or if it is even possible?