一次从另一个批处理文件运行一个文件夹中的所有批处理文件

发布于 2024-11-26 18:33:44 字数 634 浏览 2 评论 0原文

得到一个包含自动生成的批处理脚本的文件夹。例如,一个 cron 作业运行一个脚本,从数据库中获取所有新行,cURL 到我的 Windows 服务器,将批处理文件写入具有特定 ID 的文件夹。

然后,我有一个辅助批处理文件,我需要立即运行所有这些批处理文件,而不是顺序运行。原因是在任意时刻,文件夹中可能有100个批处理脚本,每个批处理脚本平均需要3分钟,即5个小时,而测试表明100个批处理脚本同时运行良好,只需要5分钟。

到目前为止,我已经:

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

它确实循环遍历所有文件,但仅按顺序运行它们。我正在考虑将每个文件名分配给一个变量并使用“&”运算符,所以它基本上是

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

但是在正确的批处理文件格式中(我在 CMD 上很糟糕)。

另外我不知道“变量”是否是全局的,因为它在每个 forfiles 上运行一个单独的 cmd 实例?

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 at 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大姐,你呐 2024-12-03 18:33:44

而不是:

Cmd /C Call @file /Q

使用:

Start Cmd.exe /Q /C @file

Start 开始一个进程并立即返回。

Rather than:

Cmd /C Call @file /Q

use:

Start Cmd.exe /Q /C @file

Start begins a process and returns immediately.

西瑶 2024-12-03 18:33:44

你不能。当且仅当执行的进程是 32 位图形 Windows 应用程序时,START 命令启动另一个进程并立即返回以执行批处理文件中的下一行。如果不是,即CMD.EXE的情况,则START等待执行的命令结束。

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.

幽蝶幻影 2024-12-03 18:33:44

上述答案的组合应该有所帮助。

假设您想要搜索位于根文件夹中的文件夹 batch_files 的内容,将给出以下内容:

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

这对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文