0

I am using python in linux and tried to use command line to print out the output log while redirecting the output and error to a txt.file. However, after I searched and tried the methods such as

python [program] 2>&1 | tee output.log

But it just redirected the output the the output.log and the print content disappeared. I wonder how I could print the output to console while save/redirect them to output.log ? It would be useful if we hope to tune the parameter while having notice on the output loss and parameter.

2 Answers 2

2

the method you found is correct. Here is an example, you can try it yourself.

''' a.py '''
print('hello world')


$ python a.py 2>&1 | tee out.log
 hello world

So I think your program may did not output correctly

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

Comments

0

You can create a screen like this: screen -L and then run the python script in this screen which would give the output to the console and also would save it the file: screenlog.0. You could leave the screen by using Ctrl+A+D while the script is running and check the script output by reattaching to the screen by screen -r. Also, in the screen, you won't be able to scroll past the current screen view.

2 Comments

screenlog.0 would be saved automatically ? to where ?
It will be saved to the directory you do screen -L.

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.