逐个执行bat文件

时间:2016-08-20 15:38:02

标签: batch-file

我得到的是一个bat文件列表:

  • file1.bat
  • file2.bat
  • ...
  • file29.bat

我需要他们一个接一个地跑。 file1.bat关闭file2.bat时开始的含义等等。

我尝试了这个,但它无法正常工作:

start /wait call file1.bat 
start /wait call file2.bat

2 个答案:

答案 0 :(得分:0)

您可能希望在问题中添加更多内容,以便更容易理解。我的猜测是你希望bat文件打开下一个文件然后关闭它。

如果那是你想做的事;将这些命令添加到每个文件中:

start file2.bat
exit

当然,您希望将start file2.bat更改为start file3.bat,依此类推每个文件。

如果您希望file1.bat管理所有文件,我认为这不是批量生产的。

答案 1 :(得分:0)

你没有描述它是如何做到你没想到的。我猜你所发生的事情是你必须在下一个脚本继续之前关闭每个脚本。

start上的文档说:

WAIT        Start application and wait for it to terminate.
command/program
            If it is an internal cmd command or a batch file then
            the command processor is run with the /K switch to cmd.exe.
            This means that the window will remain after the command
            has been run.

如果您必须使用start,那么您可以强制它使用/c开关,该开关会在完成后自动关闭窗口:

start /wait cmd /c call file1.bat

我不确定你是否通过使用call来完成任何事情,所以这应该只相当于:

start /wait cmd /c file1.bat

使用start为每个程序创建一个新窗口,您可能只想在一个命令处理器窗口中运行它。

正如Biffin所说,你可以在主脚本中列出它们,它们将按顺序运行。

call file1.bat
call file2.bat
...
call file29.bat

简而言之就是:

for /l %%f in (1; 1; 29) do call file%%f.bat

请记住将批处理脚本中的百分比字符加倍,但不要在命令行上加倍。

这个问题可能会解释您所看到的一些意想不到的行为。

How to run multiple .BAT files within a .BAT file

相关问题