0

im trying to call an executable (application/x-executable) file with arguments from within a python script. I have seen similar questions here but i still cant get it to work. when calling this file through the terminal i simply use the form:

location/of/file < output

meaning i call the function with these 2 arguments. im trying to do the following from my python script:

import subprocess

preprocess_path = "file_location"
subprocess.call([preprocess_path, '<', 'output.sas'])

but this doesnt seem to work. Any suggestions out there? Any help would be greatly appreciated.

yotamitai
  • 3
  • 2

1 Answers1

2

You should be able to do this with subprocess.Popen and using the keyword argument stdin with the input file open:

import subprocess

preprocess_path = "file_location"

with open('output.sas', 'r') as f:
    proc = subprocess.Popen([preprocess_path], stdin = f)
    proc.wait()
Farhan.K
  • 3,425
  • 2
  • 15
  • 26