Try-except error in Python -


i have python script has batch command in between,

batch_cmd = "batch command" subprocess.call(batch_cmd) 

consider scenario want repeat running batch command if fails. tried use try/except in such way batch_cmd has repeated in 'except' part too. is:

try:      batch_cmd = "batch command"     subprocess.call(batch_cmd)  except:     print "error. retrying"     subprocess.call(batch_cmd) 

the exception not getting caught, however. if batch command in try block fails, bypasses 'except' block , executes remaining of script. how can rewrite try/except part this? or there other method other try/except? know there have been similar questions on solutions have not helped me far.

if want exception in case called command fails (nonzero exit code), use subprocess.check_call(batch_cmd) execute it.

also use except subprocess.calledprocesserror: in case avoid catching more exceptions necessary.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -