How to call a system command with flexibility on Windows
Mark McEahern
mark at mceahern.com
Sun Jan 18 19:57:45 EST 2004
On Thu, 2004-01-15 at 20:09, Mark Hammond wrote:
> Some, if not all of the popen functions on Windows will return the exit
> code of the program when closing the last returned handle. I'm afraid I
> have no time to check the docs or find sample code, but it does work :)
I believe os.popen does on both cygwin and plain windows; e.g.,
cmd = 'some command'
stdout = os.popen(cmd)
print stdout.read()
exitCode = stdout.close()
if exitCode:
print '%s failed, this probably says why:\n%s' % (cmd, stdout)
Although I suppose spelling it "stdout" is misleading--doesn't popen
return stdout/stderr combined?
Cheers,
// m
More information about the Python-list
mailing list