捕获返回错误就像在unix中一样,但现在在dos / batch中

时间:2013-03-08 07:59:50

标签: windows batch-file

我更习惯使用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 /批处理文件中这样做?

1 个答案:

答案 0 :(得分:0)

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

所以,我猜测上面的unix命令在

的下面做了些什么
if %errorlevel% neq 0 echo There is no ORA-ERROR found in alert log > %ERRLOG%

注意:
我很确定带有美元符号($)的事情是变量,因此我将文件输出到变量。

希望有所帮助。