Badr Elmers
Badr Elmers

Reputation: 1706

Run a subroutine (label) in a separate window using batch?

I can call a label in the same batch using

CALL :LABEL

but I can t find a way to run it in a separate window, nothing of this works:

start "" :LABEL

cmd /c :LABEL 

start "" call :LABEL

The only way I found is calling a separate batch file, but this is not a solution because I want to have all the code in the same batch for ease of use and access. Do you know any posible solution?

Upvotes: 0

Views: 541

Answers (1)

tueftl
tueftl

Reputation: 218

As Windows batch doesn't support this, your solution may be an if at the very beginning of your batch file, checking for a specific first argument:

if "%~1"=="gotolabel" goto %~2

With this, you may insert calls to labels like this (%~dpnx0 evaluates to the path+name of your batch, %COMSPEC% evaluates to cmd.exe):

start "" "%COMSPEC%" /c "%~dpnx0" "gotolabel" LABEL

...or, without a new window:

"%COMSPEC%" /c "%~dpnx0" "gotolabel" LABEL

Upvotes: 3

Related Questions