Does anyone know if it is possible to manipulate the output of an exe when calling it from the native os module in python? For example suppose we have some executable, call it example.exe
, and when it is executed it asks the user for input, a file perhaps.
os.system('example.exe')
Enter file name:
<--- this is the output from example.exe that requires user input, i.e. I have to type the file name in
What I would like to be able to do is generate a list of the files in the cwd and then enter the files one by one as I call the script.
file_list = os.listdir(os.getcwd())
for f in file_list:
os.system('example.exe')
Enter file name: f
But I am unsure if this is possible because it requires user input and I am not sure how to mimic that from script.
Update: The issues arises because the example.exe
has no option for providing arguments, e.g. I cannot do something like example.exe filename
to provide the required input.