473,466 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Piping data into script under Win32

I trying to figure out a way to make a python script accept data output
from another process under Windows XP, but I fail miserably. I have a
vague memory having read this is not possible with Python under
Windows...

But googling for a clue I came across this from /Learning Python/ (Lutz
& Ascher) [1]
<Learning Python>

import sys
data = sys.stdin.readlines()
print "Counted", len(data), "lines."

On Unix, you could test it by doing something like:
% cat countlines.py | python countlines.py
Counted 3 lines.

On Windows or DOS, you'd do:
C:\> type countlines.py | python countlines.py
Counted 3 lines.

</Learning Python>
So: Is it possible to pipe data under DOS/Win9x but not NT/2k/XP or is
it a bug in /Learning Python/ ?
I've tried about all kinds of sane and insane approaches involving
sys.stdin, but they all results in IOError: [Errno 9] Bad file
descriptor.
[1] <http://www.oreilly.com/catalog/lpython/chapter/ch09.html>

Jul 19 '05 #1
5 2235
I can't think of any reason that wouldn't work. You've entered the
code in exactly like you have it below?

Could you paste the traceback from your console?

jw

On 15 Apr 2005 19:11:44 -0700, runes <ru*********@gmail.com> wrote:
I trying to figure out a way to make a python script accept data output
from another process under Windows XP, but I fail miserably. I have a
vague memory having read this is not possible with Python under
Windows...

But googling for a clue I came across this from /Learning Python/ (Lutz
& Ascher) [1]

<Learning Python>

import sys
data = sys.stdin.readlines()
print "Counted", len(data), "lines."

On Unix, you could test it by doing something like:

% cat countlines.py | python countlines.py
Counted 3 lines.

On Windows or DOS, you'd do:

C:\> type countlines.py | python countlines.py
Counted 3 lines.

</Learning Python>

So: Is it possible to pipe data under DOS/Win9x but not NT/2k/XP or is
it a bug in /Learning Python/ ?

I've tried about all kinds of sane and insane approaches involving
sys.stdin, but they all results in IOError: [Errno 9] Bad file
descriptor.

[1] <http://www.oreilly.com/catalog/lpython/chapter/ch09.html>

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #2
On Saturday 16 April 2005 03:11, runes wrote:
I trying to figure out a way to make a python script accept data output
from another process under Windows XP, but I fail miserably. I have a
vague memory having read this is not possible with Python under
Windows...

C:\> type countlines.py | python countlines.py
Counted 3 lines.


Are you definitely doing this and not:

C:\> type countlines.py | countlines.py

That will give you the error you're seeing. The example you posted works for
me.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBCYHpwY6W16wIJgxQRArR9AJ4vRbHQELs6d6BqUUDDNG BxAhWMhACgh4eR
Sg8+vSF93a4RR7fgFcRNJDE=
=3j2L
-----END PGP SIGNATURE-----

Jul 19 '05 #3
You being so sure about what you were saying, was what I needed.
Thanks!

Under Windows, I'm used to rely on the PATHEXT env. variable, so I
typically don't write "python scriptname.py args", but just "scriptname
args".

So:
type countlines.py | python countlines.py = Success
type countlines.py | countlines.py = Failure

Why doesn't the latter work?

Traceback:
F:\groks>type countlines.py | countlines.py
The process tried to write to a nonexistent pipe.
Traceback (most recent call last):
File "C:\groks\countlines.py", line 2, in ?
data = sys.stdin.readlines()
IOError: [Errno 9] Bad file descriptor

Jul 19 '05 #4
On Saturday 16 April 2005 03:43, runes wrote:
type countlines.py | python countlines.py = Success
type countlines.py | countlines.py = Failure

Why doesn't the latter work?


Don't quote me on this, but I think it's because invoking countlines.py
involves running some sort of wrapper that discards its stdin and stdout.

If anyone has a more authorative answer, I'd like to know, because this caught
me out too.

james.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBCYIVHY6W16wIJgxQRAjScAJ4umerCch3+aC8ORhJzNk 3i7FHrwQCfcAxl
/99yvz5++XsF5qf06rhdZic=
=fAya
-----END PGP SIGNATURE-----

Jul 19 '05 #5
Thanks James! I'll post the explanation if I find it ;-)

Rune

Jul 19 '05 #6

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

Similar topics

4
by: Christian Long | last post by:
Hi I'm trying to pipe data into a python program on Windows 2000, on the command line. Like this: dir | myProgram.py Here's what I tried:
2
by: Csaba Henk | last post by:
For me, one reason for using Python is that with the help of it I can rid of several problems that I faced with during writing scripts in Bourneish shells. Biggest of these problem was the...
0
by: Matt Price | last post by:
Hi folks, I'm writing a python script which I plan to use in a macro for mutt, the mailer. The script is supposed to generate and send an email based on a mailto: url pulled out of an email...
2
by: Apple Grew | last post by:
I want to develope a Winboard like application which will support Winboard protocol. For that I require to know how to handle piping in Python. I seperated out module popen2, but when I use...
6
by: mhenry1384 | last post by:
On WinXP, I am doing this nant.exe | python MyFilter.py This command always returns 0 (success) because MyFilter.py always succeeds. MyFilter.py looks like this while 1:
1
by: Brian Conklin | last post by:
Hello Eneryone, I am having a problem. I have written a little app that will take a text "pipe" delimited file and place all of the values in to an Excel spreadsheet. It works great on any of my...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
4
by: Thomas Eichner | last post by:
Hi, does anybody know a public website which offers a service that displays all data send by a browser (or an app calling the website), especially HTTP GET and POST data, browser data etc.? I...
1
by: James McGill | last post by:
Hi All, I'm using subprocess.Popen to run a C++ compiler and have set stdout = PIPE. The exact line of code that I am using is: process = Popen(command, stdout=PIPE) status = process.wait() ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.