473,385 Members | 1,275 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Reading from stdin (in windows)

Hi!

I wanna write a file processor in python (Windows XP).
I wanna use pipe, and not parameters.

When I write this:

....
l = []
while 1:
t = sys.stdin.read(1)
if t == '':
break
l.append(t)

t = "".join(l)
....

and use code this:
process.py <test.txt

I got:
"Bad file descriptor"

What I do wrong? I need to call this module in another format?
Or I read in wrong way?

Thanks for your help:
dd

Oct 14 '08 #1
1 1604
du*******@gmail.com wrote in news:mailman.2448.1223974725.3487.python-
li**@python.org in comp.lang.python:
Hi!

I wanna write a file processor in python (Windows XP).
I wanna use pipe, and not parameters.

When I write this:

...
l = []
while 1:
t = sys.stdin.read(1)
if t == '':
break
l.append(t)

t = "".join(l)
...

and use code this:
process.py <test.txt

I got:
"Bad file descriptor"

What I do wrong? I need to call this module in another format?
Or I read in wrong way?
The problem appear to be that MS-Windows doesn't make pipe's for
programs it opens via its file type association mechanism.

Essentially MS-Windows is treating the .py file as a document and
using python to "open" the document.

Try running you program as:

python process.py <test.txt

Note for this to work python will have to be on your path. If
it isn't use the full path to you copy of python. for e.g.:

c:\python25\python.exe process.py <test.txt

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Oct 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Harbinger of Doom | last post by:
Hello, I'm currently working on a program that has to read values from the windows registry. I use the functions "RegOpenKeyEx", "RegCloseKey" and "RegQueryValueEx" for that. If I can read the...
1
by: Lisa C | last post by:
Hi all. I am trying to set up a C++ program which will continuously read stdin from another applications stdout. I will continue reading until I read a message that will indicate to stop. Does...
6
by: chad kline | last post by:
FBSD 4.8/GCC //////// C-CODE: //////// char c; while ( 1 ) {
6
by: Charlie Zender | last post by:
Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
8
by: orium69 | last post by:
Hi! how could i know if it was written something in stdin since the last time i read it? Tks...
1
by: hecsan07 | last post by:
Hey I am trying to read the Windows Event Logc. In fact, I am able to read the Event Log. My problem is that I am reading and filtering a large log and it takes a very very very very long time...
0
by: goncoloz | last post by:
can you help me about this subject. i have a problem, which i have files in frm format on linux mysql server and i want to read this files on windows what can i do for this problem please help me...
0
by: Ichor | last post by:
Again, I'm really new to Python... How do I read text from a given window? Also, if what I want to read isn't actually text (really a picture of some sort in the form of a letter or number),...
3
by: tevo | last post by:
Hello, I'm trying to do a Perl script on Windows (wish it was Unix) that goes to a directory, figures out which files are most recent, within the last week, then copies them to another dir. I'm...
5
by: TazDev | last post by:
I'm trying to write a console program to exactly duplicate a much older dos-based program. This older program uses getch() to prompt a user for a response to a question. This program is also used...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.