0

Im trying to send all my outputs to a file,not exclusively print statements but all statements,I'm running an algorithm which gives outputs of its own and some logger outputs,

Right now Im trying

f = open('/mnt/sdc1/Ryan/Test/output_logs/{}.txt'.format(file),'w')
sys.stdout=f

but this outputs only the print statements,

I have also tried experimenting with

f = open('/mnt/sdc1/Ryan/Test/output_logs/{}.txt'.format(file),'w')
sys.stderr=f

but this too does not give me everything that the terminal outputs, Any suggestions would be helpful,Thanks in advance.

Rahul
  • 10,830
  • 4
  • 53
  • 88
  • what does 'not everything' mean? please be more precise. (did you try to `f.flush()` your out file from time to time?). – hiro protagonist Feb 27 '18 at 11:15
  • 1
    stdout and stderr are two different output streams. For your "everything" you need to catch them both, not one at a time. – Jongware Feb 27 '18 at 11:17
  • this might be helpful: https://stackoverflow.com/questions/17602878/how-to-handle-both-with-open-and-sys-stdout-nicely – hiro protagonist Feb 27 '18 at 11:17
  • I did not do f.flush(), by 'not everything' i mean when i do sys.stdout, i only get ouptuts where i have explicitly specified print in my python file,and when i try sys.stderr ,I dont get the print ones and also i dont get the logger ones,Sorry if i was unclear – DecentMakeover Feb 27 '18 at 11:18
  • @usr2564301 can i catch them both and put them in one text file? – DecentMakeover Feb 27 '18 at 11:19
  • Well I don't know about you but others can: https://stackoverflow.com/q/38776104/2564301, for example. – Jongware Feb 27 '18 at 11:21

0 Answers0