472,353 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 1842
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roman Neuhauser | last post by:
Hello, I have a piece of code that gets run in a script that has its stdout closed: import sys sys.stdout = sys.stderr c =...
4
by: Rouben Rostamian | last post by:
Consider the following demo program: #include <stdio.h> int main(void) { unsigned char c; for (c=0; c<15; c++) putchar(c);
2
by: Nadav | last post by:
Hi, Introduction: *************** I am trying to redirect stdout to a RichEdit control, this is done by initiating a StringWriter, associated...
0
by: Chuck Gantz | last post by:
I have written two programs to test some stdin/stdout redirection ideas to eventually test a legacy console application writtn in C. One of the...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should:...
1
by: Hendrik van Rooyen | last post by:
I am writing a small application with a simple ascii based menu. The menu is used to test individual functions, and to change some timings....
1
by: TP | last post by:
Hi everybody, I try to find a quick way to redirect the standard output of a Python command (for example: print "message") to a python variable...
19
by: fx5900 | last post by:
Hi, i am trying to convert an .osm (openstreetmap) file into gml format and finally to shapefile given this wiki info...
2
by: TP | last post by:
Hi everybody, The following code does not redirect the output of os.system("ls") in a file: import sys, os saveout = sys.stdout fd = open(...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.