Python or 4NT? With a question or two about popen()

Mark McEahern marklists at mceahern.com
Sun Sep 12 19:59:16 EDT 2004


On Sun, 2004-09-12 at 18:52, Robin Siebler wrote:
> And how, exactly, do I *use* popen4()?

import os
command = 'ls -al nonexistent'
fin, fout = os.popen4(command)
# I never futz with stdin.
fin.close()
output = fout.read()
exitCode = fout.close()
if exitCode:
    print 'Error running %(command)s:\n%(output)s' % locals()
else:
    print 'Success running %(command)s:\n%(output)s' % locals()

This may have minor syntactical errors or typos--since I'm not verifying
it by running it.  But mostly, the above pattern should work.

Questions?

// m




More information about the Python-list mailing list