1

I have a python script_1 which will be used to call another python script_2 using subprocess. When I do that I can see so many print statements and ouputs on the python console (or cmd). How can I redirect this output to a file along with displaying the output on the python console.

Basically, I need a windows executable command for ' | & tee ' command of Linux. I tried many methods and all those didn't work.

Thanks for the help. :)

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Dheeraj
  • 11
  • 2
  • Please share your code. – Federico Navarrete Jul 04 '18 at 08:59
  • 1
    Pure python solution: use the `logging` package with two handlers (one logging to stderr and one logging to file). – bruno desthuilliers Jul 04 '18 at 09:00
  • 2
    Possible duplicate of [Python Popen: Write to stdout AND log file simultaneously](https://stackoverflow.com/questions/15535240/python-popen-write-to-stdout-and-log-file-simultaneously) – ksbg Jul 04 '18 at 09:00
  • The easiest way in `cmd` might be `{your python command line} > file.log & type file.log`, although this will display the text only after your scripts have finished execution, of course... – aschipfl Jul 04 '18 at 12:01

0 Answers0