Please explain script and how to change

Hi all I am working on some ftp scripts but need a little help understanding a syntax.
 I like to keep the scripts clean and don't want to use a bunch of If else lines. I want to use the exit /b  and exit /b 1 more effectively, but need some guidance. Here is a sample of how I used it. Can someone please explain simply as possible the difference between exit /b and exit /b 1
if exist "D:\APTsx\apt_parent_article_ss_%NewDate%.csv" echo Unprocessed file found >>%TRACEFILE1%
if exist "D:\APTsx\apt_parent_article_ss_%NewDate%.csv" (GOTO:MOVE_FILE_TO_DESTINATION) ELSE (GOTO:GET_FILE)
>>%TRACEFILE1% echo Starting FTP GET_FILE PROCESS                               
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCPFILE1%"
COPY %TRACEFILE1% %EMAILFOLDER%\APTSX_ERROR_LOG.TXT
IF EXIST %EMAILFOLDER%\APTSX_CONNECTION_TRIGGER.TXT (
CALL "%EMAILEXE%" APT_Shrink_Spoilage_ERROR
EXIT /b 1
)
IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT (GOTO:NOTIFY_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b
)
:: BUILDING IPSWITCH SCRIPT FOR FTP PROCESS
:MOVE_FILE_TO_DESTINATION
>>%TRACEFILE2% echo Starting MOVE_FILE_TO_DESTINATION PROCESS

Open in new window

xzay1967Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
it just exits. The 1 is an exit code. All apps have them.  You can use an exit code in a script by checking errorlevel to see how it went.
Image you call scriptx.bat from scripty.bat
After that call you can say
if errorlevel=="1" goto whatever
goto endall
:whatever
rem do whatever you should if scriptx returned a 1 exit code

:endall

Se Microsoft's link for more:
http://technet.microsoft.com/en-us/library/bb490902.aspx
0
xzay1967Author Commented:
I have to admit, I am so lost with all this scripting stuff, lol. What I am trying to achieve is the following:
if xyz happens, do abc, but do not go to the next subroutine.
If xyz does not happen, go to the next subroutine. I guess I can just use the goto command and save myself the headache. I was just trying to avoid writing tons of if xyz, do or goto abc.
0
SStoryCommented:
Well,
You don't really need the Else:

IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT (GOTO:NOTIFY_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b

Open in new window


This could be written as follows:
]IF EXIST %EMAILFOLDER%\APTSX_NO_FILE.TXT  GOTO NOTIFY_EMAIL
GOTO MOVE_FILE_TO_DESTINATION

Open in new window


Either way, unless there is a return of some sort it should never get to the EXIT command.
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

SStoryCommented:
Why do you need exit codes? Are you using the results in another script or app?  If not a simple
goto end_all

and a label at the bottom

:end_all

would be fine.
0
xzay1967Author Commented:
The problem I ran into that brought me to this point is that I have a script that was not going to the next subroutine even if the error did not occur. Here is the script as is

"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCP_FILE1%"
COPY %TRACEFILE1% %EMAIL_FOLDER%\APT_LOTTERY_ERROR_LOG.TXT
IF EXIST %EMAIL_FOLDER%\CONNECTION_ERROR_TRIGGER.TXT CALL "%EMAIL_EXE%" APT_LOTTERY_ERROR
IF EXIST %EMAIL_FOLDER%\FILE_GET_ERROR_TRIGGER.TXT (
	CALL "%EMAIL_EXE%" APT_LOTTERY_FILE_GET_ERROR
	EXIT /b
) >>"%LOGFILE%"
GOTO:MOVE_FILE_TO_DESTINATION

REM
:MOVE_FILE_TO_DESTINATION
>%SCP_FILE2%  echo  TRACE %TRACEFILE2%

Open in new window



***********************
The job ran, the error file was not created, yet, the script did go to the Move_file_to_destination subroutine. The job would exit at the Exit /b command. I tried it with Exit /b 1, it did the same thing. I thought maybe I need to actually put the command Else into the syntax to make it go to the next subroutine, it still exit. Oddly I have other scripts that have the exit /b and exit /b 1 and they run fine, so not sure where I went wrong here.
0
xzay1967Author Commented:
No not calling any other scripts, I just thought I could use Exit as a way to end the if else loop so that script will continue or exit fine. But if you recommend that I get rid of the exit and use goto instead, then so be it.
0
xzay1967Author Commented:
Here is a copy of one that works using the exit code
>>%LOGFILE% echo Starting GET_FILE FTP PROCESS
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com" ftpscrpt -f "%SCPFILE%"
>>%LOGFILE% TYPE %TRACEFILE%
COPY %TRACEFILE% %EMAILFOLDER%\ARMARKETING_IN_ERROR_LOG.TXT
IF EXIST %EMAILFOLDER%\ARMARKETING_IN_CONNECTION_TRIGGER.TXT (
CALL "%EMAILEXE%" ARMARKETING_IN_ERROR
EXIT /b 1
)
IF EXIST %EMAILFOLDER%\ARMARKETING_IN_FILE_TRIGGER.TXT (GOTO:NOTIFICATION_EMAIL) ELSE (
GOTO:MOVE_FILE_TO_DESTINATION
EXIT /b
)
REM
:MOVE_FILE_TO_DESTINATION
>>%LOGFILE% echo starting MOVE_FILE_TO_DESTINATION section
>>%LOGFILE% COPY D:\ARMarketing\%WAWASHIP%_%DATESTAMP%.csv %RRSRV2%\%WAWASHIP%_%DATESTAMP%.csv
SLEEP 10
:MOVE_FILE_TO_ARCHIVE
>>%LOGFILE% echo Starting MOVE_FILE_TO_ARCHIVE section
>>%LOGFILE% MOVE %WAWASHIP%_%DATESTAMP%.csv F:\ARMarketing\Archive\%WAWASHIP%_%DATESTAMP%.csv
REM
:NOTIFICATION_EMAIL
>>%LOGFILE% echo Starting NOTIFY section
COPY %TRACEFILE% %EMAILFOLDER%\ARMARKETING_IN_LOG2_COPY.TXT
If EXIST %EMAILFOLDER%\ARMARKETING_IN_FILE_TRIGGER.TXT(
CALL "%EMAILEXE%" ARMARKETING_IN_NO_FILE
EXIT /b 1

If EXIST %RRSRV2%\%WAWASHIP%_%DATESTAMP%.csv (CALL "%EMAILEXE%" ARMARKETING_IN_SUCCESS) ELSE (
CALL "%EMAILEXE%" ARMARKETING_IN_FILE_TO_RRSRV2_ERROR
EXIT /b
)

Open in new window

0
xzay1967Author Commented:
Sorry for the confusion, I just thought about your question regarding if I am calling another batch file. I am actually calling another program, this program is a vb program that sends an email based on the error message the job generates. Those "%emailexe%" entries in the code is a variable for the email program, the entry after the variable is a section name specific to a error type such as Armarketting_in_file_to_rrsrv2_error. This means if the file is missing on rrsrv2, sn email is sent specifying that error in the subject with the log file attached. Hope that sheds some light on what my script is does.
0
xzay1967Author Commented:
Yes I am using the results of another app. In the If statement, the script looks for a text file, and if it exists, then it calls the email program to send out an email based on the error type the text file addresses.
0
SStoryCommented:
That does not matter the only reason your script needs exit with a code after it s to allow a script or app that calls your script to know how it did.  Pass or fail?

I think it is cleaner to do a single exit point at the bottom.
Use

goto end_all
At each exit point you have now



:end_all
Any exit code to cleanup goes here


However you can exit frommanywhere
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.