Created
January 4, 2014 01:01
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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