2017-03-02 28 views
1

我有兩個批處理腳本:呼叫在批處理腳本不會轉到指定的子程序在另一個批處理文件

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行都不會調用Batch_B中的「BAR」子例程。

我已經嘗試過爲:

call "%~dp0Batch_B.bat BAR" 
call "%~dp0Batch_B.bat" :BAR 
call "%~dp0Batch_B.bat" %BAR% 
call %~dp0Batch_B.bat BAR 

沒有什麼工作。我知道這可能是一些基本的東西,但是我做錯了什麼?還有其他方法可以完成這個嗎?

+0

不能完成。 – abelenky

回答

4

就我所知,您無法在另一個批處理文件中調用標籤。你可以做的是:

在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並隨後將去第二個標籤。

除此之外,您應該在:FOO部件結束後添加Goto eof,以便您也不會通過:BAR部件。

0

這是可能的,但它是如果它是一個功能或錯誤辯論。

::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. 
+0

batch_a.bat中的被調用的子將會給'%0'和'%〜nx0'帶來不同的結果。後者將返回實際文件,而'%0'命名被調用的子文件。 – LotPings