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

时间:2022-04-27 02:42:05

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 ;)

我知道我可能在这里错过了一些基本的东西,但我是一个非常文盲的人,有这样的东西,所以请善待;)

3 个解决方案

#1


1  

Below command could meet your expectation. 'master' batch file look like

以下命令可以满足您的期望。 'master'批处理文件看起来像

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"

#2


1  

to call a command means, execute it, wait until it is finished before continuing.
to start a command means, execute it in another instance of cmd and continue without waiting for it to finish.

调用命令意味着执行它,等到它完成后再继续。启动命令意味着,在另一个cmd实例中执行它并继续而不等待它完成。

So if you want to execute several programs in parallel, you should use start. The first quoted parameter is the title of the new instance (can be empty: ""). The /D parameter gives a working directory. Filenames/paths with spaces have to be quoted. So the final line would look something like:

因此,如果要并行执行多个程序,则应使用start。第一个引用的参数是新实例的标题(可以为空:“”)。 / D参数给出一个工作目录。必须引用带空格的文件名/路径。所以最后一行看起来像:

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"

#3


0  

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

#1


1  

Below command could meet your expectation. 'master' batch file look like

以下命令可以满足您的期望。 'master'批处理文件看起来像

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"

#2


1  

to call a command means, execute it, wait until it is finished before continuing.
to start a command means, execute it in another instance of cmd and continue without waiting for it to finish.

调用命令意味着执行它,等到它完成后再继续。启动命令意味着,在另一个cmd实例中执行它并继续而不等待它完成。

So if you want to execute several programs in parallel, you should use start. The first quoted parameter is the title of the new instance (can be empty: ""). The /D parameter gives a working directory. Filenames/paths with spaces have to be quoted. So the final line would look something like:

因此,如果要并行执行多个程序,则应使用start。第一个引用的参数是新实例的标题(可以为空:“”)。 / D参数给出一个工作目录。必须引用带空格的文件名/路径。所以最后一行看起来像:

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"

#3


0  

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