gpt4 book ai didi

batch-file - 如何使用 RootPath 在一个 bat 文件中运行多个 bat 文件

转载 作者:行者123 更新时间:2023-12-03 16:45:09 27 4
gpt4 key购买 nike

我想运行一个批处理文件,启动其他 4 个批处理文件。问题:只有第一个 CMD 文件被执行。

我查看了此处发布的类似问题: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 文件与 Account/Customer/Contract/Location 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 上的其他 Batch 帖子中推断出解决方案。我是这门语言的新手,如果我忽略了什么,请原谅。

欢迎任何帮助。

最佳答案

这看起来像您的 Account.cmd 重置了 RootPath。环境变量是( session )全局变量,除非您使用 setlocal 将它们隔离。要解决这个问题,您可以更改名称(就像您所做的那样)或在批处理文件中使用 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.

关于batch-file - 如何使用 RootPath 在一个 bat 文件中运行多个 bat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23630446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com