Running Python scripts under W2K with I/O redirection

S

sub1ime_uk

I apologise if this is a well known problem. I've searched and can't
find a clear description or fix. Hope someone can help.

I am running my Python scripts under Windows 2000 using Python 2.4
Build 243 from Activestate.

If I want to specify a file as standard input to my script I can just
enter a command like:

H:\> pyscript.py file.inp

and that's what I get. All ok so far.

However if I enter commands like:

H:\> type file.inp | pyscript.py

or

H:\> pyscript.py < file.inp

It doesn't work. I've also tried the variant of parsing for a command
line argument of '-' or 'filename' and then specifically either copying
the sys.stdin file object or opening the file specified, then using
that file object. Same problem.

Interestingly enough, if I specify my commands as:

H:\> type file.inp | python pyscript.py

or

H:\> python pyscript.py < file.inp

It all works the (unix-like) way I wanted it to. This leads me to
suspect there is something wrong in the way that Python is being
invoked by Windows in my problem situation rather than an inherent
fault within Python itself.

Does anyone have any idea what the problem could be and how to fix it?
I know its a really minor niggle but it'd make this poor deprived
unix-guy-forced-into-windows-servitude very happy.

Thanks, sub1ime_uk

sub1ime_uk (at) yahoo (dot) com
 
V

vincent wehren

|I apologise if this is a well known problem. I've searched and can't
| find a clear description or fix. Hope someone can help.
|
| I am running my Python scripts under Windows 2000 using Python 2.4
| Build 243 from Activestate.
|
| If I want to specify a file as standard input to my script I can just
| enter a command like:
|
| H:\> pyscript.py file.inp
|
| and that's what I get. All ok so far.
|
| However if I enter commands like:
|
| H:\> type file.inp | pyscript.py
|
| or
|
| H:\> pyscript.py < file.inp
|
| It doesn't work. I've also tried the variant of parsing for a command
| line argument of '-' or 'filename' and then specifically either copying
| the sys.stdin file object or opening the file specified, then using
| that file object. Same problem.
|
| Interestingly enough, if I specify my commands as:
|
| H:\> type file.inp | python pyscript.py
|
| or
|
| H:\> python pyscript.py < file.inp
|
| It all works the (unix-like) way I wanted it to. This leads me to
| suspect there is something wrong in the way that Python is being
| invoked by Windows in my problem situation rather than an inherent
| fault within Python itself.

Your suspicion is correct

see:

http://support.microsoft.com/default.aspx?kbid=321788

--

Vincent Wehren



|
| Does anyone have any idea what the problem could be and how to fix it?
| I know its a really minor niggle but it'd make this poor deprived
| unix-guy-forced-into-windows-servitude very happy.
|
| Thanks, sub1ime_uk
|
| sub1ime_uk (at) yahoo (dot) com
|
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top