In my batch I process a csv file, upon hitting an error in processing the playerSync.exe file the batch will loop and restart processing the csv file after the line that hit the problem. The trouble is that the next call to findstr will fail to find the error message even though it's there. The tail.bat file shows it but the call to findstr fails to see it and so the else message "some other error" gets printed and eof is reached. Or is the goto loop
line just getting skipped and the processing falling through to goto eof
somehow? The wait.bat, copycsv.bat seem to run right without problem so I doubt the trouble is in there.
So my question is why can't I find the same string with repeated calls to findstr in my batch file ?
UPDATE - NEW QUESTION: why is the goto command ignored in my batch file?
@echo. >> dataupdatelog.txt
@echo ============================================ >> dataupdatelog.txt
@echo %date% - %time% >> dataupdatelog.txt
@echo ============================================ >> dataupdatelog.txt
@echo. >> dataupdatelog.txt
@echo off
REM RENAME PlayerSyncLog.txt "PlayerSyncLog_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,4%.TXT"
rem call download.bat >> dataupdatelog.txt
SET CSVFILE=fromwebsite.csv
REM call PlayerSync.exe -SYNC %CSVFILE%
:loop
time /T
findstr /c:"Import Successful!" "PlayerSyncLog.txt" >nul 2>&1 && (
tail.bat
goto success
) || (
findstr /c:"Error found in row" "PlayerSyncLog.txt" >nul 2>&1 && (
echo "found exception error"
echo "copycsv"
copycsv.bat
time /T
RENAME PlayerSyncLog.txt "PlayerSyncLog_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,4%.TXT"
call PlayerSync.exe -SYNC %CSVFILE%
time /T
echo "wait 240"
wait.bat 240
time /T
echo "GOTO loop"
GOTO loop
echo "after GOTO loop"
) || (
echo "some other error"
GOTO success
))
:success
rem call backitup.bat >> dataupdatelog.txt
rem call upload.bat >> dataupdatelog.txt
rem call uploadlogs.bat >> dataupdatelog.txt
UPDATED CODE:
added the /I to the findstr command and also added the line echo "after goto loop"
to see if the goto was ignored and it was, the "after goto loop" gets echoed, eg output from a run is:
C:\Documents and Settings\Administrator\Desktop\website xfer>mybatch.bat
"loop"
02:52 PM
"check for error"
"found exception error"
(1 row affected)
"copycsv"
02:54 PM
"call playersync after error found"
02:54 PM
"wait 240"
02:58 PM
"goto loop"
"after goto loop"
C:\Documents and Settings\Administrator\Desktop\website xfer>
So, new question, why is the goto command ignored?
UPDATE 2: the new scripts seems to be working :
@echo. >> dataupdatelog.txt
@echo ============================================ >> dataupdatelog.txt
@echo %date% - %time% >> dataupdatelog.txt
@echo ============================================ >> dataupdatelog.txt
@echo. >> dataupdatelog.txt
@echo off
rem RENAME PlayerSyncLog.txt "PlayerSyncLog_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,4%.TXT"
rem call download.bat >> dataupdatelog.txt
SET CSVFILE=fromwebsite.csv
rem call PlayerSync.exe -SYNC %CSVFILE%
rem echo "wait 240"
rem call wait.bat 240
GOTO BEGIN
:LOOP
echo "loop"
time /T
call copycsv.bat
time /T
RENAME PlayerSyncLog.txt "PlayerSyncLog_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,4%.TXT"
echo "call playersync after error found"
call PlayerSync.exe -SYNC %CSVFILE%
time /T
echo "wait 240"
call wait.bat 240
time /T
rem END LOOP
:BEGIN
rem tail.bat
findstr /I /c:"Import Successful!" "PlayerSyncLog.txt" >nul 2>&1 && (
echo "success"
SET SUCCESS=0
) || (
echo "check for error"
findstr /I /c:"Error found in row" "PlayerSyncLog.txt" >nul 2>&1 && (
echo "found exception error"
SET SUCCESS=1
) || (
echo "some other error"
SET SUCCESS=2
)
)
echo "SUCCESS==" %SUCCESS%
if %SUCCESS% == 1 ( GOTO LOOP ) else ( GOTO END )
:END
rem call backitup.bat >> dataupdatelog.txt
rem call upload.bat >> dataupdatelog.txt
rem call uploadlogs.bat >> dataupdatelog.txt