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

Mark McEahern marklists at mceahern.com
Mon Sep 13 01:59:16 CEST 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