473,545 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.p y ==
#!/usr/bin.env python
import sys
print sys.sdtin.readl ines()
When I run it on Linux and Windows, results differ
ls -l | ./readFromStdin.p y - Works on Linux

dir | readFromStdin.p y - 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 9899
ch************@ yahoo.com (Christian Long) writes:
dir | readFromStdin.p y - 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.p y

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.p y

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.p y

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.goo gle.com:
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.u k
int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
"\6\7\xb\1\x9\x a\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #4
anonymous
98 New Member
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@rasmusse n.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
1815
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? I am a network engineer in an Active Directory environment and I have found serveral uses for python, and I need to find a book that emphasizes features of python 2.2 and programming in this type...
1
2722
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 Perl code below: $filename = $ARGV;
3
2897
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 Basic because our VP in charge of I.T. likes to have "consistency", and at the moment we're a Microsoft shop. He has assigned me the task of developing an new application, the exact nature of...
1
2369
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 on is a calculator and I would like to have a menu in the GUI option to open a command line where you can use Python commands to perfom the functions of the application within the Python command...
0
1650
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 fine, but when I try to run my script from IDLE I get: Traceback (most recent call last): File "<pathtomyscript>\main.py", line 3, in -toplevel- import pgdb File "C:\Program...
2
1885
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 'python' I get a line of gibberish and it locks up the cli, if I run the 'command' dos box I get a few lines of garbage and it crashes/closes the dos box. I've tried a re-install, checked my...
0
996
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 2005. I am unable to connect to database.What might be the problem thnks in advance
2
2224
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 things easier. How would you do that?
4
15069
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. But they do work in IDLE. please teach me about the python(command line).
0
7434
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7946
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7791
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3491
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.