Page 1 of 1

A CMD,BAT script launcher

Posted: 09 Jun 2008 16:52
by budhax
I used to add "EXIT" command at the end of my CMD scripts.
1. Is it good or bad ?

Here is bellow a CMD/BAT script launcher (Launcher.cmd).
It works fine but, if the selected launched script contains the EXIT command, the launcher process is killed (too) by this command. So, I cannot launch another script ;((

2. Is this the only way to solve my problem: "Just remove the EXIT command in all scripts" ?

3.1. Can WScript language do all or almost DOS language can do?
3.2. Do you know a WScript language tutorial/reference web site?

Thanks and regards


Code: Select all

::--------------------------------------------------------- Pour Lancer Les BAT, CMD
SET CurrFN=%~nx0
SET FileVN=FileN

ECHO.Lancez un .CMD ^^!
SET /a Ci=0
FOR /f "Delims=" %%f in ('DIR /b /on /a-d "*.CMd" "*.BAT"') DO (
   SET File=%%~nxf
   IF /i NOT "!File!"=="!CurrFN!" (
      SET /a Ci+=1
      IF !Ci! LSS 10 (ECHO.  !Ci!  !File!) ELSE (ECHO. !Ci!  !File!)
      SET !FileVN!!Ci!=!File!
SET Choix=
SET /P Choix=Choix: (1-%Ci%) ? 
IF /i  "%Choix%"=="" GOTO:FinN
IF NOT "%Choix%"=="" SET Choix=%Choix:~0,2%
SET FilCMD=!%FileVN%%Choix%!
IF EXIST "%FilCMD%" (Call "%FilCMD%") ELSE (ECHO.&ECHO.*** Choice ERROR)

ENDLOCAL&ECHO.END. BYE ..... &PING -n 3 LocalHost>Nul&EXIT ::___________________

Test.bat (put this file next Launcher.cmd, and run Launcher.cmd)

Code: Select all

ECHO.I am [%~nx0] running ...
ECHO.How to properly exit [%~nx0] without killing the script that called me ??

Posted: 30 Jun 2008 05:25
by DGMakers
Windows Help:
Quits the CMD.EXE program (command interpreter) or the current batch

EXIT [/B] [exitCode]

/B specifies to exit the current batch script instead of
CMD.EXE. If executed from outside a batch script, it
will quit CMD.EXE

exitCode specifies a numeric number. if /B is specified, sets
ERRORLEVEL that number. If quitting CMD.EXE, sets the process
exit code with that number.

so i recommend using exit /b