Link to home
Start Free TrialLog in
Avatar of elwayisgod
elwayisgodFlag for United States of America

asked on

How do I get the exit code from the executed .bat to pass back...

I had this question after viewing Can't get the script to continue.....


So the above works however my Automation tool 'Autosys' doesn't pick up the exit codes on the executed .bat.  Thus the jobs go to success no matter what.   Not sure what my options are here....  That is a wrinkle I forgot to mention and/or think of when solution provided.
Avatar of NVIT
NVIT
Flag of United States of America image

In your .bat, you can add an
exit /b 1

Open in new window

Not just value of 1 but any value you want to return.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of elwayisgod

ASKER

I'll attach the main .bat and the first two .bat scripts.   They are with .txt though.
DailyAssets.txt
FundAE_Load.txt
DailyFundExpenses.txt
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Ben

Hi.  Sorry for late response.  

1) %BatchRootFolder% is set at beginning of the scripts with:  SET BatchRootFolder=%CD%
2) Yes we have had issues with the 'call .\Scripts\local_ini.bat'.  I have been just hard-coding them as the issues come up.  It's a must the 'local_ini.bat' script gets executed or the whole thing goes awry.
3) The 'CMD /c' command was a suggested solution in the original question.  It worked until I needed exit codes to be passed for Autosys.  Thus the new question.  I'm open to a solution that works.  Sounds like CMD isn't it.
4) Are you saying to query the registry as in 'regedit' for the Reg Query option?  If so, I don't think they would want to do that.
5) Don't know what SetX is.  Let me look into that.

Basically my issue is Autosys keeps tripping over each other.  We can't have some jobs execute at same time.  So basically I'm trying to change my scripts to accommodate.   Currently there are 8 .bat scripts that execute on Autosys.  Let's call them Batch1 to Batch8.  In Autosys, only one can execute at a  given time.  So each script relies on a data file that gets created by an Informatica workflow.  So I was thinking to have a main script check for the data file and if it finds it then execute it's corresponding batch.  Go down the line and loop a few times.  Once there are no data files to process it would exit.  Autosys then goes into 'wait' mode again....

We have this .ksh script, however it has flaws and I have zero clue how to fix it.  Person who created it left the company.  Normally what we do in Autosys is we pass in the Autosys job name as a param.  I guess it's a max of 10.  We weren't aware of that either.  We execute this script as it's own 'Status' job before the actual job runs.  This job must goto SUCCESS before the actual job runs.  This is how it's executed with the 8 jobs passed in:

/lclapps/bin/autosys/rev_statuscheck10.ksh JOB1 JOB2 JOB3 JOB4 JOB5 JOB6 JOB7 JOB8

The issue with this script is it might find that  JOB5 is running.  So it waits until it's done.  Then it checks to JOB6, JOB7 and JOB8.  Those aren't running it goes to success and the real job starts.  Issue is  as it waits for jobs to complete a prior job like JOB2 might start.  So we were thinking maybe this script can be modified to loop through the jobs to make sure not previous job started?

Appreciate any ideas.
rev_statuscheck10.ksh.txt
I created a new question for the korn shell script issue.  It's related, but kind of it's own question IMO.

https://www.experts-exchange.com/questions/29016228/Korn-Shell-Script-Is-there-a-way-to-LOOP-it.html
Hi,

Tried many ways to get this to work with Autosys but couldn't get it to pass the exit codes back and forth.  Thus instead of a 'main.bat' that executes other .bat files, I just combined the 'other' .bat files into a single .bat.  Put in some 'IF' logic and it's working.

Thanks everyone for the efforts!!!
Thanks for the efforts.  Still learned a bit about the 'cmd /c'.  Appreciate the help.
Thanks. Glad you got it working