Catch返回错误就像在Unix中一样,但现在在dos/ batch中



我更习惯Unix脚本。

findstr "ORA-[0-9]" alert_%%A.log>>%output-file%

在Unix中,我可以捕获返回错误:

if [ $? -ne 0 ]; then echo "there is no ORA-ERROR found on alert log" > $ERRLOG

问题:我如何在DOS/批处理文件中做到这一点?

如果命令失败,%errorlevel%变量返回errorlevel(使用.bat扩展,而使用.cmd扩展,即使命令成功,它也会更改errorlevel)。

所以,我猜上面的unix命令在 后面做了一些事情
if %errorlevel% neq 0 echo There is no ORA-ERROR found in alert log > %ERRLOG%

注意:
我很确定以美元符号($)进行的事情是变量,所以我制作了它输出到变量的文件。

希望对你有帮助。