我正在创建一个批处理文件来自动执行 FFmpeg 重新混合和其他繁琐的步骤。我还想将这个批处理文件分发给其他人,因为它似乎对其他志同道合的人有用。
在我的代码中,我让它在早期部分打开一个应用程序,以便代码的用户可以打开他们喜欢的编辑器并测试他们的文件是否按预期工作,然后继续使用代码,但是一旦打开应用程序,批处理文件就会停止并完全关闭。
TL;DR:运行启动命令后,如何保持批处理窗口打开?
我将在下面发布前 2 个代码块,以便您了解我的意思:
@Echo off
set /p IPath=Enter the Path of the file you wish to remux from (use "Copy as path" option and keep the Quotations):
set /p M=what is the first letter of the path of your new file?(do not include the semicolon(:))
set /p NewPath=Enter the Path you wish to remux to (must be path minus the directory BUT do not use Quotations for this)(I also recommend using a single folder to hold the files while remuxing them before sending them to their separate folders):
set /P f=have you accidentally closed the process?[y/N] Please note this will skip the remuxing process and take you through the rest of the code:
if /I "%f%" == "N" goto :FFmpeg
if /I "%f%" == "Y" goto :Premiere
:FFmpeg
ffmpeg -i %IPath% -c copy -map 0 "%M%:\%NewPath%"
goto :Premiere &:: This command takes inputs from the previous lines and sets up to remux files
:Premiere &:: this command line starts the preferred editor and waits 30 seconds to allow it to start
set /p EDITOR=Enter the .exe file for your prefered editor should look like: 'Adobe Premiere Pro.exe':
echo Starting Process. . . Please Wait
start "" "%EDITOR%"
echo Starting Process. . . Please Wait
tasklist | find /I "%EDITOR%" &:: The next couple of lines test for the editor to see if it opened or not
if errorlevel 1 (
echo could not start process
goto :FailEditor
) Else (
echo Process completed, next question--->
goto :choice
)
更新:我发现使用cmd /k
该命令之前的命令将保持窗口打开,但它不会继续执行代码,它只会打开应用程序,然后转到我指定的目录
更新 2我已经尝试了/wait
命令Raven
(顺便说一句,谢谢你,这在将来会派上用场),但它对我的代码所做的只是等待应用程序关闭,然后关闭批处理文件。我想澄清一下,我试图在打开应用程序后从中断的地方继续执行代码。否则其余的代码就毫无意义了。
更新 3经过更多测试后,似乎代码在打开我的编辑器之前突然停止了(尽管这是一个旧版本)这里是它的代码
@Echo off
Setlocal
set /p newname=Enter new file name:
set /p k= keeps breaking?[Y/N]
if /I "%k%" == "Y" goto :Premeiere
if /I "%k%" == "N" goto :start
:start
ffmpeg -i "V:\Before Remux\01.mkv" -c copy -map 0 "M:\1 REMUX HUB\%newname%.mp4" /wait
goto :Premeiere
:: this command line starts premiere pro and waits 1 minute to allow it to start
:Premiere
start "Editor" "Adobe Premiere Pro.exe"
pause
goto :choice
:choice &:: This asks user to check using premiere pro or other editing sofware for corruption/file failure
set /P c=Does the final file work as intended[Y/N]?
if /I "%c%" == "N" goto :Redo &:: this will send them to Redo the remux
if /I "%c%" == "Y" goto :Foldercreation &:: if no failure/corruption is found and user confirms this will send them to :Delete
:Redo &:: This command line re-remuxes the original video then asks the question again
ffmpeg -i "V:\Before Remux\01.mkv" -c copy -map 0 "M:\1 REMUX HUB\%newname%%%.mp4"
goto :choice2
:Foldercreation &:: This section asks the user which folder it should be stored in
set /P Folder=Which folder should this go in?
echo Checking if exists directory "M:\%Folder%" ...
cd "M:\%Folder%"
if !ERRORLEVEL! GTR 0 (
echo Directory doesn't exist, creating...
md "M:\%Folder%"
goto :Foldercreation
) else (
echo Directory already exists.
)
goto :Move
:Move
move "M:\1 REMUX HUB\%newname%.mp4" "M:\%Folder%\"
set /P c3=Did the file go to the correct folder?[Y/N]
if /I "%c3%" == "Y" goto :Delete
if /I "%c3%" == "N" goto :Foldercreation
:Delete &:: This area deletes the original file to allow obs to write the next one without issue
Del "V:\Before Remux\01.mkv"
echo This video is now remuxed please edit it
echo OBS is primed for next stream!!
pause
endlocal
exit
:choice2 &:: This asks the user again just in case
set /P c2=Does this one work? If not check for corruption in original file!!![Y/N]
if /I "%c2%" == "N" goto :corrupted
if /I "%c2%" == "Y" goto :Foldercreation
:corrupted &:: if FFmpeg fails both times user is asked to check for corruption and does not delete the original file
@Echo check for corruption
pause
endlocal
exit
更新 4:我已经找到了它停止的原因。这是因为我错误地标记了一个字母,导致代码被破坏并立即停止了程序。我还学会了如何使用暂停命令进行调试。谢谢你的帮助
默认情况下
START
将在后台运行应用程序并立即继续执行批处理脚本。为了避免在后台运行命令,请使用:
强制等待执行完成后再继续
/WAIT
执行批处理脚本。START
My_Command.exe
另一种选择是在
START
命令后面放置一些使其等待的内容,例如批处理PAUSE
或循环检查以查看启动的进程是否仍在运行。只需添加下面示例的初始行和代码中的最后一行
基本上,这行代码会检查您在运行它时是否提供了参数。如果没有,它会使用“
stay
”参数重新启动,然后一直等待使用该timeout.exe
命令。对于您来说,这种机制可确保窗口在等待您按下 Enter 键(或关闭窗口)时保持打开状态,这对于保持脚本“运行”是必需的。