1

我想知道是否可以在另一个批次的特定 goto 函数中启动一个薄批次?

因此,不仅要启动另一个批处理文件,还要让“母”批处理在“子”批处理中选择一个特定的 goto 选项?

4

4 回答 4

1

只需拥有父/母批处理文件并将参数传递给子批处理文件。

妈妈.bat

@ECHO OFF
ECHO Here we go
CALL child.bat 3
PAUSE

儿童.bat

@ECHO OFF

IF "%1"=="1" Goto 1
IF "%1"=="2" Goto 2 
IF "%1"=="3" Goto 3

EXIT

:1

 ECHO 1!
 PAUSE
 EXIT

:2

 ECHO 2!
 PAUSE
 EXIT

:3

 ECHO 3!
 PAUSE
 EXIT

这个例子应该回显3!因为母批处理文件将参数3传递给子批处理文件。

于 2012-10-25T12:45:46.393 回答
1

是的,但这是一个黑客。

通常,您会在调用的批处理文件的帮助下完成此操作。

主文件

call second.bat :theFunction

*第二个.bat

goto %1

...
:theFunction

该 hack 使用了一个功能错误,您只需要与 second.bat 中相同的标签。它只有在你启动 second.bat 时才有效call

主文件

call :theFunction
echo back in main
exit /b

:theFunction
second.bat 
echo back in the func in main, this line will never reached
exit /b This line will also never reached

当 second.bat 返回时,会返回到callmain.bat之后的那一行

于 2012-10-25T12:46:44.213 回答
1

1.bat

call 2.bat /c goto :this
call 2.bat /c call :that

.

2.bat

if "%1"=="/c" shift & shift & %2 %3
goto :eof

:this
echo This!
goto :eof

:that
echo That!
goto :eof

编辑:我原来的帖子最接近正确。但我已经纠正了我的错误。

我双移以将 %1 和 %2 移到左侧,将任何其他变量传递到 %1 和 %2 位置。然后我执行 %2 和 %3 因为移位的效果在该行完成执行/解释之前不会生效。

于 2012-10-26T07:14:50.690 回答
0

在您调用的批处理文件中,将其放在顶部

if not %1=="" goto :%1

在您用来调用它的批处理文件中

call b.bat labelname

显然,这取决于您尝试做什么,但基本功能有效。

于 2012-10-25T13:35:50.250 回答