1

I have a script test.py which is used for server automation task and have other script server.py which list out all server name.

server.py list all sevrer name in text.log file and this log file is used by test.py as a input.

I want one single script test.py to execute server.py from inside it and also redirect server.py script output to text.log file as well.

So far i have tried with execfile("server.py") >text.log in test.py which didn't worked.

1 Answer 1

4

Use subprocess.call with stdout argument:

import subprocess
import sys

with open('text.log', 'w') as f:
    subprocess.call([sys.executable, 'server.py'], stdout=f)
    # ADD stderr=subprocess.STDOUT  if you want also catch standard error output
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.