Exit Code Needed

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Exit Code Needed

Post by mightycpa » Thu Feb 08, 2018 3:37 pm

Hi,

I'm using the runtime to run MS scripts from SQL Server jobs. At the end of my MS scripts, I want to return exit codes, so that my calling script can branch to the correct next step, depending on success, failure and the nature of the failure. The problem is, that doesn't seem to work:
Exit>[return_code]

Immediately terminates the current script. When used in a compiled macro you can set the executable's return code with return_code.
A compiled macro! What about the runtime? What can I do instead, given that I cannot run compiled scripts? Here's the only thing I can think of:

Code: Select all

Let>IGNOREERRORS=1
...
//Force a crash
If>v_exit_code>0
  Let>IGNOREERRORS=0
  Add>a,b
Endif

Yikes! Have any better ideas?

EDIT: I think I understand why you might not want to return error codes to Windows/DOS from the Editor, but I wonder if that is something technically difficult to do with the runtime, or if you just never considered including that feature. If it's the latter, it would be useful for the same reasons I'd want to step through scripts in the runtime.

Thanks.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Exit Code Needed

Post by Marcus Tettmar » Mon Feb 12, 2018 9:43 am

Only executables can return exit codes. It doesn't make sense from "the runtime" as you keep calling it because when you run scripts on the command line the software may already be running and remain running.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Exit Code Needed

Post by mightycpa » Wed Feb 14, 2018 5:21 pm

Marcus Tettmar wrote:It doesn't make sense from "the runtime" as you keep calling it because when you run scripts on the command line the software may already be running and remain running.
What would you like me to call it instead? The client runtime?
Marcus Tettmar wrote:Only executables can return exit codes.

That's not correct. A little googling reveals that a Windows batch file, uncompiled, can return an exit code.

Code: Select all

exit /b 123
Armed with this knowledge and a little cleverness, I've found that I am now able to return custom error codes from non-compiled macro scheduler scripts executed using the client runtime that my SQL Server jobs can read. I just couldn't do it the way I first expected to be able to do it.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Exit Code Needed

Post by Marcus Tettmar » Wed Feb 14, 2018 6:05 pm

Code: Select all

What would you like me to call it instead? The client runtime? 
Well I think you're just calling scripts via the command line. So you're just running Macro Scheduler itself. I'm not clear whether you're using the runtime clients we offer with the enterprise package, but in any case, when it comes to running macros via the command line there's no difference between this and the regular Macro Scheduler. But in your initial post a while back you seemed to be trying to pass macros to the compiler. Hence some confusion. I *think* for the purposes of clarity for this forum you are simply running macros via the macro scheduler command line.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts