469,921 Members | 2,198 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 2154
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Christian Long | last post: by
2 posts views Thread by Csaba Henk | last post: by
reply views Thread by Matt Price | last post: by
2 posts views Thread by Apple Grew | last post: by
1 post views Thread by Brian Conklin | last post: by
6 posts views Thread by tatamata | last post: by
4 posts views Thread by Thomas Eichner | last post: by
1 post views Thread by James McGill | last post: by
reply views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.