NEWBIE: Extending Python with C
Wolfgang Strobl
wks000 at t-online.de
Sun Nov 10 07:50:19 EST 2002
Alex Martelli <aleax at aleax.it>:
>This is more or less the end of the line in terms of what
>os.popen can offer -- due to buffering and suchlike there's
>no practical way for python to drive BOTH standard input
>and standard-output of another external program.
Well, the following snippet, driving nslookup.exe on W2K works for me:
import sys,os
print sys.version
popen2=os.popen2
i,o=popen2("nslookup","t")
def prnt(f):
print "(---"
c=None
while c!=">":
c=f.read(1)
sys.stdout.write(c)
print "---)"
prnt(o)
while(1):
cmd=raw_input()
if cmd=="stop":
i.write("exit\n")
break
print "cmd:",cmd
i.write(cmd+"\n")
prnt(o)
print "feddich"
C:\e\littlepython>cmddriver.py
2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)]
(---
Standardserver: www-proxy.BN1.srv.t-online.de
Address: 212.185.249.50
>---)
www.python.org
cmd: www.python.org
(---
Server: www-proxy.BN1.srv.t-online.de
Address: 212.185.249.50
Name: fang.python.org
Address: 194.109.137.226
Aliases: www.python.org
>---)
stop
feddich
--
Wir danken für die Beachtung aller Sicherheitsbestimmungen
More information about the Python-list
mailing list