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
Active
Viewed 73 times
-2

Omar Yacop
- 305
- 1
- 6
3 Answers
1
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

crooksey
- 8,521
- 6
- 30
- 52
-
I need to get the result in form of text to save it in a .txt file, does your code achieve that? – Omar Yacop Aug 05 '22 at 09:11
-
Yes, read up on stdout https://stackoverflow.com/questions/3385201/confused-about-stdin-stdout-and-stderr – crooksey Aug 05 '22 at 11:33
-
I have been reading for an hour and didn't find what I want, are you sure. All what I found was to get a long response from a command. – Omar Yacop Aug 05 '22 at 12:47
0
Why don't you use this from terminal
python main.py > output.log

AnhPC03
- 622
- 5
- 15
-
I need the program to save it to a text file, I don't want to do it manually – Omar Yacop Aug 05 '22 at 08:56
0
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.

Viet
- 1
- 2
-
I need the program to save it to a text file, I don't want to do it manually – Omar Yacop Aug 05 '22 at 08:57