Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file how to call another batch file at a specified label or call and immediately goto a certain label?

I am trying to figure out how file1.bat can call file2.bat at a specified label.

I figured I can do it like this:

File1.bat

:config
@echo off
:setvars
set labelmarker=labelmarker
call file2.bat
pause > nul
:EOF

File2.bat

if %labelmarker%==labelmarker goto label4
:label1
echo it won't work...
goto EOF
:label2
echo it must work!
goto EOF
:label3
echo it didn't work...
goto EOF
:label4
echo it works!
goto EOF
:EOF

This works. but I want to call a bat AND the Label from file1.bat. is it possible with a control character or ascii code or anything? like i tried

call file2.bat | goto label4 - doesn't work
call file2.bat > goto label4 - doesn't work
call file2.bat @label4 - doesn't work

Any help would be greatly appreciated.

Even if it involves extracting a specific label and contents to a new file would be ok.

like image 515
Chris Hayden Avatar asked Jul 20 '12 09:07

Chris Hayden


1 Answers

You could pass the label you want to go to as a parameter

Example scripts

First.bat

@echo off
set label=GOHERE
call Second.bat %label%
pause >nul

Second.bat

@echo off
goto %1
echo This line should be skipped
:GOHERE
echo Jumped here
like image 81
Bali C Avatar answered Oct 26 '22 19:10

Bali C