2014-05-13 127 views
1

我想運行一個批處理文件,該文件啓動4個其他批處理文件。 問題:只有第一個CMD文件被執行。如何使用RootPath在bat文件中運行多個bat文件

我看着這裏發表類似的問題:How to run multiple .BAT files within a .BAT file
這裏:How do I launch multiple batch files from one batch file with dependency?

我的問題不同的是,我沿着每個CMD文件ROOTPATH通過。

Examples given in other posts: 
call msbuild.bat 
call unit-tests.bat 
call deploy.bat 

My code: 
SET RootPath="G:\Dev Folder\Framework\MainFolder\SubFolder\JOBS\" 
CALL %RootPath%Account.CMD 
CALL %RootPath%Customer.CMD 
CALL %RootPath%Contract.CMD 
CALL %RootPath%Location.CMD 

包含代碼這Master.CMD文件不在同一目錄中的帳戶/客戶/合同/位置CMD文件,這就是爲什麼我傳遞的絕對路徑。 第一個命令運行得很好。然後我得到的錯誤:

'..\Customer.CMD ' is not recognized as en internal or external command, operable program or batch file. 
'..\Contract.CMD ' is not recognized as en internal or external command, operable program or batch file. 
'..\Location.CMD ' is not recognized as en internal or external command, operable program or batch file. 

我不能從其他批處理帖子推演出的解決方案在stackoverflow。我不熟悉這種語言,請原諒我是否忽略了某些內容。

任何和所有的幫助是受歡迎的。

+0

RootPath裏面有一個空格。嘗試使用引號「CALL」%RootPath%Account.CMD「'。 –

+1

這看起來像你的'ACCOUNT.CMD'重置'RootPath'.Env變量是全局變量,除非你用'setlocal'將它們隔離開來。 – wmz

+0

RootPath值有引號。 此外,爲** CALL「%RootPath%Account.CMD」添加引號**似乎無法解決問題 – NetFlash

回答

1

這看起來像你的Account.cmd重置RootPath。除非將它們與setlocal隔離,否則Env變量是(會話)全局變量。要解決您可以更改名稱(如您所做的那樣)或在批處理文件中使用setlocal。無論如何,這通常是很好的做法,因爲它有助於避免意外/不必要的副作用。 以下是help setlocal的報價:

Begins localization of environment changes in a batch file. Environment changes made after SETLOCAL has been issued are local to the batch file. ENDLOCAL must be issued to restore the previous settings. When the end of a batch script is reached, an implied ENDLOCAL is executed for any outstanding SETLOCAL commands issued by that batch script.