title: Cannot redirect output when I run Python script on Windows using just script's name
body: <p>This is running on Windows 7 (64 bit), Python 2.6 with Win32 Extensions for Python.</p>
  
  <p>I have a simple script that just print "hello world". I can launch it with <code>python hello.py</code>. In this case I can redirect the output to a file. But if I run it by just typing <code>hello.py</code> on the command line and redirect the output, I get an exception.</p>
  
  <pre><code>C:&gt; python hello.py
  hello world
  
  C:&gt; python hello.py &gt;output
  
  C:&gt; type output
  hello world
  
  C:&gt; hello.py
  hello world
  
  C:&gt; hello.py &gt;output
  close failed in file object destructor:
  Error in sys.excepthook:
  
  Original exception was:
  </code></pre>
  
  <p>I think I first get this error after upgrading to Windows 7. I remember it should work in XP. I have seen people talking about this bug <a href="http://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html" rel="noreferrer">python-Bugs-1012692 | Can't pipe input to a python program</a>. But that was long time ago. And it does not mention any solution.</p>
  
  <p>Have anyone experienced this? Anyone can help?</p>