سؤال

I have one python file a.py. I am returning from the file using sys.exit(some_val).

Now, I have one more file b.py, from which I am executing a.py like below:

proc = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
output, error = proc.communicate()

Can you please let me know if there is any way to get the value (which is returned by using sys.exit() from a.py) from b.py?

هل كانت مفيدة؟

المحلول

Use proc.returncode:

print "a.py exited with code {0}".format(proc.returncode)

نصائح أخرى

You can get the return code from proc.returncode, but calling a python program from another python program via subprocess seems a stange thing to do...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top