我有两个批处理脚本:
Batch_A
echo You are in Batch A
call "%~dp0Batch_B.bat" BAR
Batch_B
:FOO
echo You are in Batch A and you have failed.
:BAR
echo You are in Batch A and you have succeeded.
对于我的生活,无论我采用哪种方式进行语法化,第一批中的第2行都不会调用" BAR" Batch_B中的子程序。
我已经尝试过:
call "%~dp0Batch_B.bat BAR"
call "%~dp0Batch_B.bat" :BAR
call "%~dp0Batch_B.bat" %BAR%
call %~dp0Batch_B.bat BAR
没有任何作用。我知道这可能是一些基本的东西,但我做错了什么?有没有其他方法可以实现这个目标?
答案 0 :(得分:5)
据我所知,你不能在另一个批处理文件中调用标签。你能做的是以下几点:
Batch_B.bat中的:
Goto %~1
:FOO
echo You are in Batch A and you have failed.
:BAR
echo You are in Batch A and you have succeeded.
在Batch_A.bat
中call "%~dp0Batch_B.bat" BAR
因此,这将在Batch_B.bat中评估为Goto Bar
,然后转到第二个标签。
除此之外,您应在Goto eof
部分结束后添加:FOO
,这样您就不会通过:BAR
部分。
答案 1 :(得分:1)
这是可能的,但如果它是一个功能或错误,它就会受到争议。
::Batch_A.bat
@Echo off
echo You are in (%~nx0)
call :BAR
timeout -1
Goto :Eof
:BAR
echo You are in (%~nx0) (%0)
:: this runs's the batch without a call
"%~dp0Batch_B.bat" %*
:: Batch_B.bat
Goto :Eof
:FOO
echo You are in (%~nx0) and you have failed.
Goto :Eof
:BAR
echo You are in (%~nx0) and you have succeeded.
Goto :Eof
> batch_a
You are in (Batch_A.bat)
You are in (Batch_A.bat) (:BAR)
You are in (Batch_B.bat) and you have succeeded.