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.

2
  • Try using Popen instead of call Commented Feb 14, 2018 at 14:28
  • I have found it always good practice to call the file within the project, by using ./filename.output Commented Feb 14, 2018 at 14:49

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.