2

Running python code through Control-M Jobs.If below code exit with status 7 in python. Control-m should capture code and on do Action if status 7 then code should set As Ok and should mail through Control-m.

try:
   fh = open("testfile", "r")
   fh.write("This is my test file for exception handling!!")
except IOError:
   print "Error: can\'t find file or read data"
   exit(7)

Code is terminating with exit status 7 but in control-m not able to capture exit status. In Control-m, On do Action i added if status 7 then Job should Set As Ok and should send mail.

Can someone help me how Control-M can capture Python code exit status?

saikrishna
  • 59
  • 8

2 Answers2

2

The working code would look like this (based on Amiram's comment)

import sys

try:
   fh = open("testfile", "r")
   fh.write("This is my test file for exception handling!!")
except IOError:
   print "Error: can\'t find file or read data"
   sys.exit(7)
Zajo
  • 31
  • 7
0

You can run script with bashscript and echo exitcode of python script.

critrange
  • 5,652
  • 2
  • 16
  • 47