469,349 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

Redirection of stdout fails on Windows

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
Jul 18 '05 #1
1 1813
Joel Wagner wrote:
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Roman Neuhauser | last post: by
4 posts views Thread by Rouben Rostamian | last post: by
2 posts views Thread by Nadav | last post: by
reply views Thread by Chuck Gantz | last post: by
13 posts views Thread by souissipro | last post: by
1 post views Thread by Hendrik van Rooyen | last post: by
19 posts views Thread by fx5900 | last post: by
2 posts views Thread by TP | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.