1

I call an exe tool from Python:

args = '-i' + inputFile
cl = ['info.exe', args]
subprocess.call(cl)

How would I redirect output from the info.exe to out.txt?

1 Answer 1

5

You can redirect output to file object by specifying it as stdout argument to subprocess.call. Put it in a context manager to write to file safely.

with open('out.txt', 'w') as f:
    subprocess.call(cl, stdout=f)

Or open the file in wb mode and use subprocess.check_output:

with open('out.txt', 'wb') as f:
    f.write(subprocess.check_output(cl))
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.