【问题标题】:I have a batch file. When I run it I want it to open files using another batch file. But how?我有一个批处理文件。当我运行它时,我希望它使用另一个批处理文件打开文件。但是怎么做?
【发布时间】:2021-07-07 18:36:09
【问题描述】:

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

batch1.bat F:\_FFMPEG_\bin\01.gif
timeout /T 25
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\
batch1.bat F:\_FFMPEG_\bin\02.gif
timeout /T 25
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\
batch1.bat F:\_FFMPEG_\bin\03.gif
timeout /T 25
move F:\_FFMPEG_\bin\_*.gif F:\_FFMPEG_\bin\_FILES_\

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

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

但是.. 我一运行文件就得到这个错误:

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

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

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

【问题讨论】:

  • 您是否正在使用 RUNAS Administrator 从上下文菜单执行基本批处理文件?就我个人而言,我认为你对这一切都是错误的。如果您向我们展示每个批处理文件中的内容,我们可以轻松地将您的代码压缩到一个批处理文件中并使其更具动态性。
  • 您应该使用Call "batch1.bat" "filepath\file.ext",并且应该由于使用正确的命令,然后能够删除您的每一行timeout您只需确保batch1.bat 不以Exit 结尾。 您还应该注意您没有提供到batch1.bat 的路径,因此它必须位于当时的当前目录是called。
  • @Jale,请使用tour。然后阅读How to Ask 一个好问题,然后提供一个minimal reproducible example of ALL 您正在使用的代码。
  • @Jale 使用edit 链接用相关信息更新您的问题。
  • @Compo 成功了! OMG 我太高兴了,非常非常感谢!!! ??????

标签: batch-file cmd command


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    欲了解更多信息,请访问此问题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
    

    parent.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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多