开发者

Running all batch files in a folder from another batch file at once

Got a folder which contains automatically generated batch scripts. For example - a cron job runs a script, grabs all new rows from a database, cURLs to my windows server, writes a batch file to the folder with the specific ID.

I then have a secondary batch file which I need to run all these batch files at once, not sequentially. The reason for this is at any one time, there can be 100 batch scripts in the folder, taking on average 3 minutes each, which is five hours, while testing shows that all 100 are fine running a开发者_运维问答t once, and only takes 5 minutes.

So far I have:

FORFILES /S /P "./batch_files" /M *.bat /C "cmd /c call @file /Q "

Which does loop through all the files, however only runs them sequentially. I was thinking assigning each file name to a variable and using the "&" operator so it would basically be

FORFILES /S /P "./batch_files" /M *.bat /C "cmd /c variable = variable+"&"+@fname /Q "
call variable

But in proper batch file formatting (I suck at CMD).

Also I don't know whether "variable" would be global, as it runs a separate instance of cmd on every forfiles?


Rather than:

Cmd /C Call @file /Q

use:

Start Cmd.exe /Q /C @file

Start begins a process and returns immediately.


You can't. The START command start another process and returns immediately to execute the next line in a Batch file IF AND ONLY IF the executed process is a 32-bits Graphical Windows application. If not, that is the case of CMD.EXE, then START waits for the executed command to end.


A combination of the above answers should help.

Assuming you are wanting to search the contents of folder batch_files located in the root folder would give the following:

FORFILES /S /P "\batch_files" /M *.bat /C "cmd /C start call @file"
EXIT /B

This worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜