2

I'm creating a batch file to automate FFmpeg remuxing and other tedious steps within. i also want to distribute this batch file out to others because it seems like it would be useful to others like minded.

In my code I have it open up an application in an early part of it so that the user of the code can open their preferred editor and test if their file works as intended, then continue with the code however once it opens the application the batch file stops and completely closes.

TL;DR: How do I keep the batch window open after running the start command?

I will post the first 2 code blocks below so that you can see what I mean:

@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
)

Update: I have found using the cmd /k just before that command will keep the window open but it doesn't continue the code, it just opens the application then goes to the directory I specified

Update 2 I have tried the /wait command per Raven (Thank You by the way that will come in handy in the future) but all it did on my code was wait for the application to close then it closed the batch file. I would like to clarify that I'm trying to continue the code from where it left off after opening the application. else the rest of the code is pointless.

Update 3 After more testing it seems the code just stops abruptly now before opening my Editor (albiet this was an older version) here is the code for it

@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

Update 4: I have since found out the reason it was stopping. it was becasue i mislabled with a single letter which broke the code and stopped the program immediately. I have also learned how to debug using pause commands. thank you for helping me

1 Answer 1

2

By default START will run the app in the background and continue the Batch script immediately.

To avoid running the command in the background, use:

START /WAIT "Title Here" My_Command.exe

The /WAIT forces START to wait for the execution of My_Command.exe to finish before continuing the Batch script.

The other alternative would be to put something after the START command which makes it wait, such as a Batch PAUSE or checking in a loop to see if the process you launched is still running.

4
  • so what if i just wanted to open the application then test to see if the application was open, but not have to wait for it to close to continue the process When i tested the wait command it waited for the application to close then immediately closed the batch file, my main thing is trying to prevent that and continue the code from where it left off after opening the application Commented Aug 15 at 20:39
  • What are your trying to accomplish? If you use /WAIT, the Batch file resumes once the app quits. If you don't use /WAIT the Batch file continues immediately. It's up to you to put code in the Batch file after the START command which you want to run after.
    – Raven
    Commented Aug 16 at 9:08
  • for some reason once the application starts the batch file shuts down and doesnt continue, im not sure why. it just doesnt continue at all once it opens Commented Aug 16 at 17:07
  • What command is after your START command? How do you know it's not running the command(s) after?
    – Raven
    Commented Aug 18 at 11:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .