在我的批处理中,我处理csv文件,在处理playerSync.exe文件时遇到错误,批处理将循环并重新启动处理csv文件后遇到问题的行。麻烦的是,对findstr的下一次调用将无法找到错误消息,即使它在那里。 tail.bat文件显示它,但是对findstr的调用无法看到它,因此打印了else消息“其他错误”并且达到了eof。或者goto loop
行刚被跳过,处理以某种方式落到goto eof
? wait.bat,copycsv.bat似乎没有问题,所以我怀疑麻烦在那里。
所以我的问题是为什么我不能在批处理文件中重复调用findstr找到相同的字符串?
更新 - 新问题:为什么我的批处理文件中忽略了goto命令?
@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
更新代码:
将/ I添加到findstr命令并添加了行echo "after goto loop"
以查看goto是否被忽略,并且是“后goto循环”得到回应,例如来自运行的输出是:
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>
所以,新问题,为什么忽略goto命令?
更新2:新脚本似乎正在运行:
@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