我在for循环中处理文件时试图捕获java异常。但是,尽管在循环运行时显示了java异常,但errorlevel总是等于0.
还有另一种方法可以捕获java异常,或者我的代码可能错了吗?
for /f %%a in ('dir /b /s %input%') do (
CALL jhove -m PDF-hul -h xml -o %output%\%%~na.xml %%a
if %ERRORLEVEL% EQU 0 (
echo errorlevel equals %Errorlevel% )
if %ERRORLEVEL% GEQ 1 (
echo error )
set /a loop3+=1
)
例外是这样的:
Verarbeite GBV85882115X
java.lang.ClassCastException: edu.harvard.hul.ois.jhove.module.pdf.PdfSimpleObject cannot be cast to edu.harvard.hul.ois.jhove.module.pdf.PdfDictionary
at edu.harvard.hul.ois.jhove.module.PdfModule.readDocCatalogDict(PdfModule.java:1344)
at edu.harvard.hul.ois.jhove.module.PdfModule.parse(PdfModule.java:521)
at edu.harvard.hul.ois.jhove.JhoveBase.processFile(JhoveBase.java:803)
at edu.harvard.hul.ois.jhove.JhoveBase.process(JhoveBase.java:588)
at edu.harvard.hul.ois.jhove.JhoveBase.dispatch(JhoveBase.java:455)
at Jhove.main(Jhove.java:292)
errorlevel equals 0
答案 0 :(得分:0)
java错误会在错误流中打印出来。可能会打印出来(未经测试):
set "print="
for /f %%a in ('dir /b /s %input%') do (
for /f "tokens=* delims=" %%A in ('jhove -m PDF-hul -h xml -o %output%\%%~na.xml %%a 2^>^&1') do (
echo %%A | find "ClassCastException" >nul 2>&1 && (
set print=1
)
if defined print echo %%A
)
)