Skip to content

Instantly share code, notes, and snippets.

@beatak
Created January 4, 2014 01:01
Show Gist options
  • Save beatak/8250029 to your computer and use it in GitHub Desktop.
Save beatak/8250029 to your computer and use it in GitHub Desktop.
understanding subprocess.Popen() and getting return code i always forget how it works…
#! /usr/bin/env python
import argparse
parser = argparse.ArgumentParser( description='w/e' )
parser.add_argument( '-code', type=int, help='exit code' )
args = parser.parse_args()
if args.code:
exitcode = args.code
else:
exitcode = 0
print exitcode
exit( exitcode )
#! /usr/bin/env python
import os.path
import subprocess
path_origin = os.path.dirname( os.path.abspath( os.path.realpath( __file__ ) ) )
path_exec = os.path.join( path_origin, 'exitter.py' )
proc = subprocess.Popen(' '.join([path_exec, ('-code=%d' % 0)]), shell=True, stdout=subprocess.PIPE)
meta_ps = proc.communicate()
print meta_ps
print proc.returncode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment