简体   繁体   English

如何从单个“主”批处理文件在不同位置同时运行多个批处理文件?

[英]How can I run multiple batch files concurrently in different locations from a single 'master' batch file?

These different batch files are functioning fine when executed individually, but for convenience I have been trying to execute them all at once from one location to save me from navigating through the many different sub-folders to execute them one by one. 这些不同的批处理文件在单独执行时可以正常工作,但是为了方便起见,我一直尝试一次从一个位置一次执行所有这些批处理文件,以免我浏览许多不同的子文件夹来一次执行它们。

I would have thought that my first testing attempt featuring a few of the batch files would work: 我本以为我的首次测试功能将包含一些批处理文件,但可以成功:

    CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo\Sins_text_to_bin.bat"
    CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Enhanced 4X Mod - Git Clone\GameInfo\Sins_text_to_bin.bat"
    CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Star Wars Interregnum - Git Clone\GameInfo\Sins_text_to_bin.bat"

But when I ran this nothing happened besides the cmd window appearing for a split second and then closing, with none of the referenced batch files executed. 但是,当我运行该命令时,除了cmd窗口出现一秒钟然后关闭,什么都没有发生,没有引用的批处理文件被执行。

After multiple attempts, the only thing that half worked was: 经过多次尝试,只有一半有效的是:

    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo"
    CALL "Sins_text_to_bin.bat"
    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Enhanced 4X Mod - Git Clone\GameInfo"
    CALL "Sins_text_to_bin.bat"
    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Star Wars Interregnum - Git Clone\GameInfo"
    CALL "Sins_text_to_bin.bat"

But that does not run the batch files concurrently; 但这不会并发运行批处理文件。 instead it executes them one after the other. 相反,它一个接一个地执行它们。

I know I'm probably missing something elementary here, but I am pretty much an illiterate pleb with stuff like this, so please be kind ;) 我知道我可能在这里缺少一些基本知识,但是我几乎是一个文盲,喜欢这样的东西,所以请客气;)

Below command could meet your expectation. 下面的命令可以满足您的期望。 'master' batch file look like “主”批处理文件看起来像

START "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo\Sins_text_to_bin.bat" CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo\Sins_text_to_bin.bat"
START "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Enhanced 4X Mod - Git Clone\GameInfo\Sins_text_to_bin.bat" CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Enhanced 4X Mod - Git Clone\GameInfo\Sins_text_to_bin.bat"
START "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Star Wars Interregnum - Git Clone\GameInfo\Sins_text_to_bin.bat" CALL "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Star Wars Interregnum - Git Clone\GameInfo\Sins_text_to_bin.bat"

to call a command means, execute it, wait until it is finished before continuing. call命令意味着执行它,等到它完成后再继续。
to start a command means, execute it in another instance of cmd and continue without waiting for it to finish. 若要start命令,请在另一个cmd实例中执行该命令,然后继续执行而无需等待其完成。

So if you want to execute several programs in parallel, you should use start . 因此,如果要并行执行多个程序,则应使用start The first quoted parameter is the title of the new instance (can be empty: "" ). 第一个带引号的参数是新实例的标题(可以为空: "" )。 The /D parameter gives a working directory. /D参数给出一个工作目录。 Filenames/paths with spaces have to be quoted. 带有空格的文件名/路径必须加引号。 So the final line would look something like: 因此,最后一行如下所示:

start "title" /d "<my folder>" "<my program>"

or in your case: 或者您的情况:

start "" /D "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo" "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo\Sins_text_to_bin.bat"

I found a solution! 我找到了解决方案!

The attempt that I posted above in the second code window that I said "half worked" was close. 我上面在第二个代码窗口中所说的“成功一半”的尝试已结束。 It seems that the call command when used in this way forces the first batch process to finish before the next one begins. 似乎以这种方式使用call命令会强制第一个批处理进程在下一个批处理进程开始之前完成。

If you want all of your referenced batch files to execute concurrently as I do, then the start instead of the call command is what will work: 如果您希望所有引用的批处理文件像我一样并发执行,则可以使用start而不是call命令:

   cd "\directory\bat1\"
   start bat1.bat
   cd "\directory\bat2\"
   start bat2.bat
   cd "\directory\bat3\"
   start bat3.bat

Which in my specific case using my example attempts earlier looks like this: 在我的示例中,使用我的示例尝试过的尝试如下所示:

    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\GameInfo"
    start Sins_bin_to_text.bat
    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Enhanced 4X Mod - Git Clone\GameInfo"
    start Sins_bin_to_text.bat
    cd "C:\Steam\steamapps\common\Sins of a Solar Empire Rebellion\Mods-Rebellion v1.83\Star Wars Interregnum - Git Clone\GameInfo"
    start Sins_bin_to_text.bat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM