Evil os.popen()POSIX os.popen() call is at holy war with windows - one of the reasons there are almost no crossplatform Python scripts that wrap and control 3rd party processes. For example, study this os.popen() call reported in this thread:
out = os.popen("nslookup", "w")
On POSIX machine it will call nslookup, send a string on its input and nslookup will print the result on console:
> Server: 10.0.80.11
Under windows nslookup won't output anything on screen, but it will process the input correctly and that can be proved by redirecting output to a file:
out = os.popen("nslookup > output.txt", "w")
The workaround suggested in Python bug #1366 and used in Mercurial doesn't seems to work with Python 2.5.4 on XP. According to Mercurial patch the following code should give output on console:
out = os.popen('"nslookup 2> NUL:"', "w")
but it doesn't. It still executes though, but it is not what you want if the main thing your code does is output pagination. To work around this inherently evil feature of os.popen() smart guys invented subprocess module.
out = subprocess.Popen("nslookup", stdin=subprocess.PIPE)
According to Python bugtracker, subprocess is capable to guard you against malicious os.popen() in many different ways finding natural ways to deal with evilness #3144, evilness #602245, #...
..to be continued