how to catch the sys.exit value in one program from other program in python

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?

Answers


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...


Need Your Help

How to retrieve an image's size using dom in html/javascript?

javascript html

I'm trying to get the size of an image in javascript, using this kind of code:

Request to a IIS server (when ASP NET WebForms + MVC co-exist)

c# asp.net asp.net-mvc-4 iis .net-4.5

Well, there are many questions on SO which proves that you have the possibility to hold both ASP WebForms as well as ASP NET MVC Applications running together.