Python run another script from a python script
<pre><code>def run_cmd(self, cmd):
    print cmd 

    status = os.system(cmd)
    print 'Command ran with Status: %s' % status

    if status:
        s = 'Command Failed: Status: %s for %s' % (status, cmd)
        print s
        sys.exit(status)
    else:
        s = 'Command Success: %s' % cmd 

    return status
</code></pre>

<p>I am using this function to run a python script from another script.</p>

<p>Ex: </p>

<pre><code>command_to_exec = 'python script_b.py'
run_cmd(command_to_exec)
</code></pre>

<p>Now if script_b.py fails script_a.py exits with the status.</p>

<p>That's okay. </p>

<p><strong>Case 2</strong>:</p>

<pre><code>command_to_exec = 'python script_a.py --options'
rum_cmd(command_to_exec)
</code></pre>

<p>This case is script_a.py running 'python script_a.py' from itself.
In this case, if newly spawned script_a.py fails, the outer script_a.py is still a success, because it wasn't able to catch the failure of inner script_a.py (because of sys.exit(status))</p>

<p>Now, how do I handle this situation? (If inner script_a fails, outer script_a should exit)</p>