Answer the question
In order to leave comments, you need to log in
Why BAT script works correctly only after the second run?
Hello! I wrote a simple script that should run the desired exe file with a parameter in a loop, with a pause between each run.
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET PROGRAM_PATH=D:\Program Files (x86)\Notepad++\notepad++.exe
SET LAUNCH_TIMEOUT=3
set mList=1.txt 2.txt 3.txt
(for %%m in (%mList%) do (
echo %%m launch
"!PROGRAM_PATH!" %%m
echo %%m launched
TIMEOUT /T "!LAUNCH_TIMEOUT!"
))
pause
echo %%m launched
. If you close it and run it again, then all 3 files open. Subsequent launches also work correctly. Answer the question
In order to leave comments, you need to log in
Two points:
1. Parentheses are special characters in cmd, so they must be escaped:
I have the x64 version of notepad++, so I didn't check the brackets myself.
2. When you run a third-party application from a batch file, as you do, cmd waits for this application to complete and only then continues the script execution further.
To remove this expectation, you need to start using the start command as follows:
The first quotes are the title of the new window, in this case it does not matter, because notepad++ will set its title.
In general, your script worked for me after I corrected the path to notepad++ and added start.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question