Re: Batch Mode Return Code by WindowsDavid Bailey,http://www.dbaileyconsultancy.co.uk

*To*: mathgroup at smc.vnet.net*Subject*: [mg64245] Re: Batch Mode Return Code by WindowsDavid Bailey,http://www.dbaileyconsultancy.co.uk*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>*Date*: Wed, 8 Feb 2006 03:53:32 -0500 (EST)*References*: <ds1rt1$fli$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

LectorZ wrote: > Hi guys, > > I created a package.m which I run in a batch with a runmybatch.bat. > The package.m contains a bunch of initialization cells. Every cell does > a calculation to be executed. > The output is a graph.jpg > I schedule my bat file to be run twice a day. > > Question: > How can I configure the batch file so that if at least one cell in > package.m returns an error, math.exe returns ONE and if every cell in > package.m has been executed without an error - then math.exe returns > ZERO. > I need this to automaticly control the execution of the Mathematica > jobs. > > Many thanks! > LZ > I tested Quit[n] and although it closes the MathKernel session, the integer error code did not seem to be transmitted back to the command shell. However, since you are generating a file, why not erase this and test to see if the file exists (from within the batch file) after the Mathematica code has run. This leaves the matter of ensuring that if any of your commands generate an error they exit early rather than just struggling on and generating a plot file anyway. If you wrap commands that might fail in Check you can specify the action to be taken if an error occurs - Check[command,Quit[]] However, it is probably better to isolate known problems explicitly - for example, test to see if an input file exists, rather than just waiting for the mistake to cause an error. David Bailey http://www.dbaileyconsultancy.co.uk