Redirection of stdout fails on Windows

J

Joel Wagner

I have a simple test program tst.py:

import os
os.system('echo a b c')

When run like this:

python tst.py > out

I get the expected string 'a b c' in the file 'out'.

When run like this:

tst > out

I get an error message 'The handle is invalid' and nothing in the file 'out'.

Using ActiveState Python 2.2.2 on Windows/XP Pro.

Any ideas on what the root cause is?

Thanks,

Joel
 
D

Daniel Dittmar

Joel said:
python tst.py > out

I get the expected string 'a b c' in the file 'out'.

When run like this:

tst > out

I get an error message 'The handle is invalid' and nothing in the
file 'out'.

This is a bug in cmd.exe. If script is started by looking at the extension
and then finding the real executable through the registry, redirection does
not work.

I think the easiest work around is to create batch files for every python
script you want to execute.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top