472,353 Members | 1,244 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.

Piping data into Python on the command line - Windows 2000

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:

== readFromStdin.py ==
#!/usr/bin.env python
import sys
print sys.sdtin.readlines()
When I run it on Linux and Windows, results differ
ls -l | ./readFromStdin.py - Works on Linux

dir | readFromStdin.py - Doesn't work on win2000
IOError: [Errno 9] Bad file descriptor

The ultimate goal is to write python scripts that I can use from
Komodo's (Python IDE) Run Command feature. I'm running Komodo on
Windows 2000.

I want to highlight some text in Komodo, and run my command, pasting
the output of my program back in to the file I was editing in Komodo.

Komodo makes this easy with built-in commands like sort. You just
select the "Pass Selection As Input" and "Insert Output" options,
highlight some text, type "sort" in the Run Command box, and voila,
Komodo pipes your highlighted text to sort, and pastes the sorted text
back into your editor window.

I want to write a Python program that can behave in the same way as
sort does, for use with Komodo on Windows 2000.

Thanks!

Christian Long
Jul 18 '05 #1
4 9777
ch************@yahoo.com (Christian Long) writes:
dir | readFromStdin.py - Doesn't work on win2000
IOError: [Errno 9] Bad file descriptor


I don't know if you're saying you have a problem with Komodo, or just
during your specific tests, but the above case (presuming that you're
running this from a standard Windows command, cmd.exe) is a bug in
Windows cmd.exe. When trying to use I/O redirection and registered
file extensions to automatically find an executable, the redirection
doesn't work properly. If you change this command to:

dir | python readFromStdin.py

it should work (replace "python" with the full path to your python.exe
if it isn't in your path).

Whether or not this affects Komodo's Run box depends on just how
Komodo starts up the child process. It's possible that Komodo is just
executing cmd.exe and passing in its command, in which case supplying
a Python script directly may trigger the same bug as above (or it may
not since it's actually the stdin/stdout to cmd.exe and thus Komodo
that is being passed to the Python script). If it doesn, then I
expect you'll need to be explicit about Python being the executable
you are running. Either that or maybe write a wrapper batch file
which can contain the explicit reference to python, to avoid having to
type it into the Komodo Run box.

BTW, another alternative to your script would be:

import fileinput

for line in fileinput.input():
print line,

which will work both with data on stdin as well as having filenames
specified on the command line if desired (also similar to how the Unix
sort command and many other Unix utilities work). It also doesn't
need to bring all the input into memory before processing (although
you could get that with your prior script by using readline() rather
than readlines()). The main drawback is that it's not the fastest way
to process lines, but its performance has gotten better in recent
Python releases due to general improvements in file I/O processing.

-- David
Jul 18 '05 #2
David Bolen <db**@fitlinxx.com> schreef:
I don't know if you're saying you have a problem with Komodo, or just
during your specific tests, but the above case (presuming that you're
running this from a standard Windows command, cmd.exe) is a bug in
Windows cmd.exe. When trying to use I/O redirection and registered
file extensions to automatically find an executable, the redirection
doesn't work properly. If you change this command to:

dir | python readFromStdin.py

it should work (replace "python" with the full path to your python.exe
if it isn't in your path).


I don't know if this is a bug in cmd.exe, but at least command.com on Win9x
does know nothing about "registered extensions" unless you use the "start"
command.

dir | start readFromStdin.py

This works but "start" opens a new window that is closed when the script
exits (you don't get the time to read the output).

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Jul 18 '05 #3
ch************@yahoo.com (Christian Long) wrote in news:88**************************@posting.google.c om:
I'm trying to pipe data into a python program on Windows 2000, on the
command line.

Like this:
dir | myProgram.py

This is a well known problem with Windows command line processor.
Try searching Google groups for "Python pipe win2k" and you will
find several similar threads.

e.g.
http://groups.google.co.uk/groups?th...vanderbilt.edu

Try running your command with an explicit call to the Python interpreter:

dir | python myProgram.py

--
Duncan Booth du****@rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #4
I've been writing an ANSI parser for the windows console so that I can view my python output with colours, etc, and I found the same problem.

Changing the launching of the python script to explicitly use the python interpreter helps, WTF!

Thanks Guys!

Norman

--
- Norman Rasmussen
- Email: norman@rasmussen.co.za
- Home page: http://norman.rasmussen.co.za/
Sep 18 '05 #5

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

Similar topics

3
by: Ryan Smith | last post by:
Hello All, I am new to the list and python community as well. I was wondering if anyone knows of any good python books emphasizing Windows 2000? ...
1
by: Edward WIJAYA | last post by:
Hi, I am new to Python, and I like to learn more about it. Since I am used to Perl before, I would like to know what is Python equivalent of...
3
by: Mike Moum | last post by:
Hi, I'm a civil engineer who also doubles as chief programmer for technical applications at my company. Most of our software is written in Visual...
1
by: Andrew McCall | last post by:
Hi Folks, I am building an application under multiple OS's, and I wanted to give my application For example, the test application I am working...
0
by: h112211 | last post by:
Hi all, I'm using the Windows version of Python 2.4.3 and everything worked okay until I installed PyGreSQL. Well, in fact the installation went...
2
by: Mick Duprez | last post by:
Hi All, I've installed Python 2.5 on a number of machines but on one I'm having problems with the CLI. If I fire up the 'cmd' dos box and type...
0
by: watashi | last post by:
hello everyone, I am using Visual studio 2005 VC# windows application, Operating system is windows 2000 professional and database is sql server...
2
by: orangemonkey | last post by:
I know you can use cd "name of file path" to change the address but I want the address to be a certain filepath once I open the command line to make...
4
by: fang | last post by:
Dear all: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work....
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
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
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: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
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: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
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.