我正在编写批处理文件以读取AML_handshake.txt日期并将日期与昨天的日期进行比较。如果它匹配并且最后一行= EOF则执行我的java程序。到目前为止,我已经吼到了。
@ECHO OFF
SET CURRENTDATE=%DATE%
SET LOGFILE_DATE=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
SET LOGFILE_TIME=%TIME:~0,2%.%TIME:~3,2%
SET LOGFILE="C:\Extractor\log\AML_Data_Auto-%LOGFILE_DATE%-%LOGFILE_TIME%.log"
call :Logit >> %LOGFILE%
exit /b
:Logit
set "firstLine"
for /f "tokens=*" %%A in (C:\Extractor\AML_handshake.txt) do (
If not defined firstLine set "firstLine=%%A"
set Lastline=%%A
)
REM *** FIRST CHECK ***
if "EOF" NEQ "%Lastline%" goto fail
REM *** SECOND CHECK ***
IF "%CURRENTDATE%" NEQ "%firstLine%" goto fail
exit /b
goto prog
:prog
echo Incremental Data Extraction - Started
sqlplus -s ***** @call_proc.sql
echo Incremental Data Extraction - Ended
echo Generating AML Files - Started
start "C:\Extractor" TableExtractor.exe
echo Generating AML Files - Ended
echo Process Completed
:fail
echo Initial Check Failed, Process Terminated
要进行测试运行,我已将txt文件日期修改为当前日期并执行批处理文件,但在日志文件中,我总是看到"初始检查失败,处理已终止"。
Bellow是文本文件。
01-JUN-2016
PORT_DATA|560538
NDB_AML_AA|43063
NDB_AML_LD|12878
NDB_AML_REPO|496
NDB_AML_TRAN|84596
NDB_AML_JOINT_AC|219873
NDB_AML_CUS_REL_PRTY|43
NDB_AML_BICCODE|108292
CUSTOMER_MASTER|684124
CATEGORY.MASTER|3288
DEPT.MASTER|2527
COUNTRY.MASTER|251
CUSTOMER.STATUS.MASTER|26
INDUSTRY.MASTER|65
JOB.TITLE.MASTER|22
COMPANY.MASTER|121
TRANSACTION.MASTER|3133
RELATION.MASTER|56
NDB_AML_TBILL_TBOND|2845
EOF
我想知道两件事。
1)如何比较文本文件日期和日期-1(昨天的日期), 2)为什么即使我编辑文本文件日期,我的批处理文件也没有运行?
答案 0 :(得分:2)
批处理文件中存在一些错误,包括一些难以检测的错误,例如将变量设置为末尾有一些额外空格的值,这导致您的条件进行比较,例如" EOF"用" EOF"。因此,请务必在 SET var = value 行的末尾删除多余的空格。
此外,您需要使用延迟扩展,因为您在 FOR循环中设置了变量值。这是批量的修订版本,应该执行您正在寻找的内容,并记录更多信息。
@ECHO OFF
setlocal EnableDelayedExpansion
SET CURRENTDATE=%DATE%
SET LOGFILE_DATE=%DATE:~4,2%.%DATE:~7,2%.%DATE:~10,4%
SET LOGFILE_TIME=%TIME:~0,2%.%TIME:~3,2%
SET LOGFILE=AML_Data_Auto-%LOGFILE_DATE%-%LOGFILE_TIME%.log
:Logit
set firstLine=
set lastLine=
for /f "delims=" %%A in (handshake.txt) do (
if "!firstLine!"=="" set firstLine=%%A
set lastLine=%%A
)
set err=
if "EOF" NEQ "!Lastline!" (
set err=LastLine should not be equal to "!Lastline!"
goto fail
) else (
if "%CURRENTDATE%" NEQ "!firstLine!" (
set err=FirstLine is "!firstLine!" but today's date is "%CURRENTDATE%"
goto fail
)
)
echo Incremental Data Extraction - Started >> %LOGFILE%
sqlplus -s ***** @call_proc.sql >> %LOGFILE%
echo Incremental Data Extraction - Ended >> %LOGFILE%
echo Generating AML Files - Started >> %LOGFILE%
start "C:\Extractor" TableExtractor.exe >> %LOGFILE%
echo Generating AML Files - Ended >> %LOGFILE%
echo Process Completed >> %LOGFILE%
goto :eof
:fail
echo Initial Check Failed, Process Terminated with error: %err% >> %LOGFILE%
exit /b
就将文本文件日期与昨天的日期进行比较而言,问题是has already been answered。