2014-05-13 214 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.