[英]How do I call a batch file from a batch file without creating a new window?
I need to process some audio files. 我需要处理一些音频文件。 Each file must go through multiple sequential steps, for which I've written a batch file.
每个文件必须经过多个顺序的步骤,为此我编写了一个批处理文件。 But I want all the files in the folder to be processed in parallel, for speed.
但是我希望并行处理文件夹中的所有文件,以提高速度。 So I've written another batch file which calls the first, in a loop.
因此,我编写了另一个批处理文件,该文件在循环中调用了第一个。 But when I do that, I end up with multiple command windows, which stay open even when the batch file has closed.
但是,当我这样做时,最终会遇到多个命令窗口,即使该批处理文件已关闭,它们仍保持打开状态。
In order of preference, how can I either (a) not have the windows open at all, or (b) have the windows minimised then close when finished; 按照优先顺序,我如何(a)完全不打开窗口,或者(b)最小化窗口,然后在完成时关闭;或者 or (c) have the windows open then close when finished.
或(c)打开窗户,然后关闭窗户。
for %%I in (*.mp3) DO (
start convert-mp3-to-m4b.bat "%%I"
)
I've managed to achieve (c), with start cmd /c convert-mp3-to-m4b.bat "%%I" /B
, but that was more by luck than judgement. 我已经成功实现了(c),
start cmd /c convert-mp3-to-m4b.bat "%%I" /B
,但是运气比判断start cmd /c convert-mp3-to-m4b.bat "%%I" /B
。
With the help of @Stephan I've ended up with this: 在@Stephan的帮助下,我得到了以下结果:
for %%Z in (*.mp3) DO (
start "converting-audio" /min cmd /c convert-mp3-to-m4b.bat "%%Z"
)
This starts the windows minimised, and closes them after processing. 这将最小化启动窗口,并在处理后将其关闭。 I was also glad of the
max <n>
trick, although I had to adapt the code a bit. 我也为
max <n>
技巧感到高兴,尽管我不得不稍微修改一下代码。 In case it's helpful to anyone else, my script now looks like this: 如果对其他人有帮助,我的脚本现在看起来像这样:
@echo off
setlocal enabledelayedexpansion
set count=0
set max=4
for %%Z in (*.mp3) DO (
call :loop
start "converting-audio" /min cmd /c convert-mp3-to-m4b.bat "%%Z"
)
goto :eof
:loop
for /f "tokens=* USEBACKQ" %%G IN (`tasklist /fi "windowtitle eq converting-audio" ^| find "cmd.exe" /C`) do ( SET "count=%%G" )
if !count! GEQ !max! call :loop
This processes the files four at a time, and works brilliantly. 这样可以一次处理四个文件,并且效果出色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.