我有一个批处理文件。当我运行它时,我希望它使用另一个批处理文件打开文件。但是如何?

时间:2021-04-12 16:51:03

标签: batch-file cmd command

所以我有一个批处理文件,它使用 ffmpeg 在动画 gif 文件中插入帧,我们称之为“batch1”。 不幸的是,该批处理文件只能处理 1 个 gif 文件,所以这意味着我不能在其上放置(比如说)25 个 gif 文件并让它发挥其魔力。由于我不知道如何解决这个问题,我想也许我可以制作另一个批处理文件,让我们称其为“batch2”并使用它来使用“batch1”打开文件。像这样:

  + CategoryInfo          : ObjectNotFound: (npm:String) [], CommandNotFoundException
  + FullyQualifiedErrorId : CommandNotFoundException

依此类推,直到第 25 个 gif 文件。

batch1.bat 获取 gif 文件,在某些帧上插入叠加层,并在文件名前用 _ 保存它。超时是因为在gif文件中插入overlay需要一些时间,通常是20秒。

但是..一旦我运行该文件,我就会收到此错误:

'batch1.bat' 不是内部或外部命令,也不是可运行的程序或批处理文件。

当我在 CMD 窗口中运行命令时,它工作得很好。

谁能启发我并告诉我我做错了什么?

2 个答案:

答案 0 :(得分:0)

有关更多信息,请访问此问题 How to execute a batch script (child.bat) from a batch file (parent.bat)?

为了将控制权传递回父批处理文件,必须使用 CALL 命令调用子批处理文件。

CALL batch1.bat F:\_FFMPEG_\bin\01.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\

CALL batch1.bat F:\_FFMPEG_\bin\02.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\

CALL batch1.bat F:\_FFMPEG_\bin\03.gif
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\

例如

child.bat

@echo off
echo Child Batch File is running !!!
echo Doing some Important Child Batch Stuff here . . . .
echo ✔ Child Batch Completed it. Voila !!
echo Now exiting Child.bat

父.bat

@echo off
echo Parent Batch File is running !!!
echo Doing some Important Stuff here . . . .
echo ✔ Completed it. Voila !!
echo Now running Child.bat . . .

echo -------------------------------------------------------

child.bat   
rem Comment: Some how below statements are not executing
echo -------------------------------------------------------

echo ✔ Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.

这将运行:

C:\Users\abc> parent.bat

Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat

C:\Users\abc>

不会执行其他语句。

要更正此问题,请使用 CALL :

child.bat 不会改变

@echo off
echo Child Batch File is running !!!
echo Doing some Important Child Batch Stuff here . . . .
echo ✔ Child Batch Completed it. Voila !!
echo Now exiting Child.bat

parent.bat 使用 CALL 执行 *.bat 脚本

@echo off
echo Parent Batch File is running !!!
echo Doing some Important Stuff here . . . .
echo ✔ Completed it. Voila !!
echo Now running Child.bat . . .

echo -------------------------------------------------------

rem Comments: CALL will execute the .bat and return the cmd context back to the parent.bat for further execution.
CALL child.bat   

echo -------------------------------------------------------

echo ✔ Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.

输出:

Parent Batch File is running !!!
Doing some Important Stuff here . . . .
✔ Completed it. Voila !!. .
Now running Child.bat . . .
-------------------------------------------------------
Child Batch File is running !!!
Doing some Important Child Batch Stuff here . . . .
✔ Child Batch Completed it. Voila !!
Now exiting Child.bat
-------------------------------------------------------
Completed it. Voila !!
echo I believe all the this are complete.
echo I am now exiting.

一些参考资料:

CALL | Microsoft Docs

答案 1 :(得分:0)

用户 Compo 给出了解决方案和正确答案。

@For %%G In (%*) Do @Call "batch1.bat" "%%~G" && Move /Y "%%~dpG_*.gif" "%%~dpG_FILES_"

这就是它所需要的,它现在可以完美运行! ?

相关问题