Code: Select all
C:\Users\user> A.cmd
Waiting for 1 seconds, press a key to continue ...
Code: Select all
@echo off
(goto) 2>nul || B.cmd
Code: Select all
@echo off
(goto) 2>nul || "%SystemRoot%\system32\timeout.exe" /t 1
Moderator: DosItHelp
Code: Select all
C:\Users\user> A.cmd
Waiting for 1 seconds, press a key to continue ...
Code: Select all
@echo off
(goto) 2>nul || B.cmd
Code: Select all
@echo off
(goto) 2>nul || "%SystemRoot%\system32\timeout.exe" /t 1
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set var=0
(
call echo #Main:1 var=!var! "%%0"
call :func
call echo #Main:6 var=!var! Back in Main "%%0"
)
echo #Main:9 THIS LINE WILL NEVER BE REACHED
exit /b
:func
setlocal
set /a var+=1
setlocal
set /a var+=1
setlocal
set /a var+=1
(
call echo #Func:2 var=!var! "%%0"
endlocal
call echo #Func:3 var=!var! "%%0"
(goto) 2> nul
call echo #Func:4 var=!var! "%%0"
(goto) 2> nul
call echo #Func:5 var=!var! "%%0"
)
echo #func:6 THIS LINE WILL NEVER BE REACHED
#Main:1 var=0 "myBatch1.bat"
#Func:2 var=3 ":func"
#Func:3 var=2 ":func"
#Func:4 var=0 "myBatch1.bat"
#Func:5 var=!var! "%0"
#Main:6 var=!var! Back in Main "%0"
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set var=0
(
call echo #Main:1 var=!var! "%%0"
call :func
call echo #Main:6 var=!var! Back in Main "%%0"
)
echo #Main:9 THIS LINE WILL NEVER BE REACHED
exit /b
:func
setlocal
set /a var+=1
setlocal
set /a var+=1
setlocal
set /a var+=1
(
call echo #Func:2 var=!var! "%%0"
endlocal
call echo #Func:3 var=!var! "%%0"
EXIT /B
call echo #Func:4 var=!var! "%%0"
(goto) 2> nul
call echo #Func:5 var=!var! "%%0"
)
echo #func:6 THIS LINE WILL NEVER BE REACHED
(goto) allows some more control over the program flow.#Main:1 var=0 "myBatch2.bat"
#Func:2 var=3 ":func"
#Func:3 var=2 ":func"
#Main:6 var=0 Back in Main "myBatch2.bat"
#Main:9 THIS LINE WILL NEVER BE REACHED