From: Andrew S. <str...@as...> - 2006-03-08 17:07:25
|
Hi Darren, >Does anyone know how to catch exit status using os.popen and friends? > You may want to switch to subprocess.py. It comes with Python 2.4, but it's backwards compatible with Python2.3 (maybe older). We could just include it alongside the modules that want to use it. It's pretty easy to use and is meant to unify all the various ways of executing a subprocess. Here's an example from some other code of mine (a recursive build tool that seeks out directories with setup.py and builds them with setuptools). It should be a good example of using subprocess. args = [sys.executable,'-c',"import setuptools; execfile('setup.py')"] args.extend(commands) print dir,':',' '.join(args) sub = subprocess.Popen(args, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) sub.wait() if sub.returncode != 0: print '-='*20 print '*** The following call failed:' print args stdout = sub.stdout.read() if len(stdout): print '*** stdout was:' print stdout stderr = sub.stderr.read() if len(stderr): print '*** stderr was:' print stderr print '-='*20 sys.exit( sub.returncode ) |