0

Is there any way to print stdout while at the same time also printing to a text file? For example:

import sys
sys.stdout = open('file.txt', 'w')
#The stuff below should be printed out and at the same time being printed to a text file
print "This is in a text file and stdout"

So, once again, is there any way to do this? Or can it not be done?

Ethan Bierlein
  • 3,353
  • 4
  • 28
  • 42

1 Answers1

2

If this is in a script, have a look at the unix command tee. This will allow you to split stdout into two directions, one that goes to a file, and one that simply continues to stdout

Stankalank
  • 1,507
  • 1
  • 12
  • 12