原文发布时间:2010-04-13
作者:Peri
FME有自定义的批处理功能,在File—Batch Deploy中可以配置,但是这个批处理有个缺陷,当数据源有错误或者其它原因导致模板运行失败时,整个批处理过程就会终止,不能再继续执行。
我在进行批处理时,自己定义了一段批处理脚本,自定义执行的FME模板、数据源路经、目标数据路径、以及日志等信息,代码如下:
@ECHO OFF
:: The following line is necessary for ERRORLEVEL capture.
SetLocal EnableDelayedExpansion
SET OUTPUT=.\output
SET LOG=.\logs
SET FAILED=.\failed
SET SOURCE=.\dxt
SET REPORT=report2.txt
:: If the directories don't exist, later commands run into problems
MD %OUTPUT%
MD %LOG%
MD %FAILED%
:: It is probably a good idea to delete the existing log files
:: If you don't, the report might not be accurate.
DEL /Q %LOG%\*.*
:: The following command creates the report file
:: showing date, time, and FME build. First line It is offset for formatting
:: Use >> if you want to append to an existing report file
ECHO This translation run started on %date% at %time% using> %REPORT%
fme | find "Build" >>%REPORT%
:: The FOR loop runs the actual translation and moves the files
:: If the FIND finds SUCCESSFUL in the log, the load translation is run.
:: Otherwise, the file is placed in the FAILED directory.
FOR %%F IN ("%SOURCE%\*.dxt") DO (
fme ss.fmw --SourceDataset_DGNV8 "%%F"^
--DestDataset_DGNV8 "%OUTPUT%\%%~nF.dxt"^
--LOG_FILE "%LOG%\%%~nF_convert.log"
FIND "Translation was SUCCESSFUL" %LOG%\%%~nF_convert.log >> %REPORT%
IF !ERRORLEVEL! EQU 0 (
ECHO %%F PASSED convert with ERRORLEVEL !ERRORLEVEL! >> %REPORT%
) ELSE (
ECHO %%F FAILED LOADING with ERRORLEVEL !ERRORLEVEL! >> %REPORT%
FIND "|ERROR |" %LOG%\%%~nF_convert.log >> %REPORT%
COPY /Y "%%F" "%FAILED%"
)
)
:: Just to be helpful, let's list the failed files in the report file
ECHO. >> %REPORT%
ECHO The following files failed translation: >> %REPORT%
DIR /B %FAILED% >> %REPORT%
EndLocal
pause
————————————————————————————————————
说明:
1) 参数设值
SET OUTPUT=.\output ——指定输出路径
SET LOG=.\logs ——指定日志路径
SET FAILED=.\failed ——指定错误数据存放路径
SET SOURCE=.\dxt ——指定数据源路径
2) 模板调用
fme ss.fmw --SourceDataset_DGNV8 "%%F"^
--DestDataset_DGNV8 "%OUTPUT%\%%~nF.dxt"^
--LOG_FILE "%LOG%\%%~nF_convert.log"
ss.fmw是调用的模板名称;
--SourceDataset_DGNV8 ——数据源的格式,注意DGNV8的使用,
针对不同的数据类型,设置不同
"%%F" ——数据源文件名
--DestDataset_DGNV8 ——目标数据的格式
"%OUTPUT%\%%~nF.dxt" ——输出数据的路径、名称
--LOG_FILE ——日志文件格式
"%LOG%\%%~nF_convert.log" ——日志文件路径、名称
————————————————————————————————————
这个批处理过程的的优点主要有几个:
1) 模板运行失败时,程序不会终止,能继续执行;
2) 可以将执行失败的原数据文件分离出来,并单独保存,提供分析和再处理;
3) 生成日志汇总表report