I am having an issue with a section of code designed to count the number of times a string appears in a text file. It will work perfectly when pasted into command prompt, but when run as a .bat file it immediately closes before completing (It doesn't perform the pause before the last echo command).
set Logpath="C:\Users\bob\Desktop\project\a.txt"
set StringToLookFor="asdf"
set NUM=0
for /F %N in ('find /C %StringToLookFor% ^< %Logpath%') do set NUM=%N
pause
echo %NUM%
cmd /k
to the top of the bat file to keep the terminal open after you dbl click it (or do the link+do not close option). This will show you the error... it might be failing before the pause. – Gabriel Jul 30 '20 at 23:34