1

I am running a Transporter command, which prints a log of what is happening to the prompt.

How would I re-direct all the print statements to a separate file called transporter_log.txt in the same folder as the script is running from? Something like -

log_file = open(PATH, 'w') subprocess.call(shlex.split("/usr/local//iTMSTransporter -m verify...") log_file.write(...) 

2 Answers 2

3

You could specify the file as stdout parameter:

with open(PATH, 'wb') as log_file: subprocess.check_call(cmd, stdout=log_file) 

The output of cmd is written to log_file.

Sign up to request clarification or add additional context in comments.

1 Comment

subprocess.call(cmd, stderr=log_file), since the print statements go in stderr
0

What about using the redirect command (in on unix)?

your_python.py > /path/to/transporter_log.txt 

1 Comment

It's a script that has a lot of commands, but for this specific command, I need to redirect the output (i.e., the print statements that it generates).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.