How to get the terminal full history

Question:

I am trying to save everything my python app printed in the cmd, every solution I found was to get the response of a command line using Popen from Subprocess; what I want is to get everything. Is there a built-in function for this purpose? or should I do it manually, which I don’t prefer?

Asked By: Omar Yacop

||

Answers:

Why don’t you use this from terminal

python main.py > output.log
Answered By: AnhPC03

you can try the script command in your shell. It saves everything printed out to your shell from the moment you call it. End the command with exit. you can call it from your python script, hope it helps.

script manual page

Answered By: Viet

What you want to do, is log the output of stdout, see this answer:

Making Python loggers output all messages to stdout in addition to log file

Answered By: crooksey
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.