win32: I try to script a command-line application on Windows2000, no luck so far

Tim Roberts timr at probo.com
Fri Mar 7 02:43:53 EST 2003


Christian Aastorp <christian.aastorp.killspam at siemens.no> wrote:
>
>I'm trying to control a number of command-line tools from python on
>Windows2000. I need to start the tools, give parameters, and capture
>the console output.
>
>I've done some tests with popen2.popen2 and win32pipe.popen2, but am
>unable to get the desired results, any pointers are most welcome!

If these are commands that only do output, the built-in popen command will
work.  However, popen2 seems to work fine for me:


C:\WINDOWS>python
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import popen2
>>> (pout,pin) = popen2.popen2('sort')
>>> pin.write('zzz\n')
>>> pin.write('yyy\n')
>>> pin.write('ddd\n')
>>> pin.close()
>>> print pout.read()
ddd
yyy
zzz

>>>
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.




More information about the Python-list mailing list