NEWBIE: Extending Python with C

Alex Martelli aleax at aleax.it
Sun Nov 10 10:39:01 EST 2002


Wolfgang Strobl wrote:

> 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:

So nslookup.exe on W2K does no more than line-buffering on its output, and 
reads its input repeatedly, too.  Bully for it (for the sole purpose of 
controlling both its stdin and stdout with pipes).  Most programs aren't as 
skittish with their stdin and stdout once they determine they aren't 
terminals.  On Linux, for example, running the same script you've posted 
gives:

(---
Note:  nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead.  Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
> www.python.org

and here it hangs forever -- I think nslookup is writing the prompt to
standard-error in this case, reserving stdout for output, e.g.:

[alex at lancelot examples3]$ echo www.python.org | nslookup 2>/dev/null
Server:         192.168.0.12
Address:        192.168.0.12#53

www.python.org  canonical name = fang.python.org.
Name:   fang.python.org
Address: 194.109.137.226

[alex at lancelot examples3]$


Alex




More information about the Python-list mailing list