Exit code when python script has unhandled exception -


I need a method to run a dragon script file, and if the script fails with unrestricted exception python one Non-Ezro exit code My first attempt was to do something like this:

  import case if __name__ == '__main__': try: import & lt; Unknown script & gt; Except: sys.exit (-1)   

But it breaks many scripts, because __ main___ guard is often used to do it properly Have any suggestions for?

Python is already asking you:

  $ Python -c "Increase runtime error ()" tracebacks (most recent call final): File "& lt; string"; Line 1, & lt; Module & gt; Runtime $ $ echo $? After some edits from OP, you might want to:  
  import subprocess proc = subprosec POPEAN (['/ usr / bin / python', 'script-name']) proc.communicate () if proc.returncode! = 0: # Run Failure Code Second: # Run happy code.   

Correct me if I'm confused here.

Comments