lijie98
lijie98

Reputation: 617

Capture the java exception in bat file

In my project, I call java program from the command window. I have a bat file like the following. I throw a RuntimeException in Test class. With "|| exit /b 1", all the commands after ""%JAVA_HOME%\bin\java" -cp "bin/" Test %RUN_ARGS% || exit /b 1" will be skipped.

Can anybody tell me what "|| exit /b 1" does? What is the meaning of "||" in the command line?


@echo off
setlocal

set RUN_ARGS=%*

"%JAVA_HOME%\bin\java" -cp "bin/" Test %RUN_ARGS% || exit /b 1

echo %RUN_ARGS%

dir

endlocal
exit /b 0

Upvotes: 0

Views: 1781

Answers (2)

JayG
JayG

Reputation: 632

exit /B exits the batch file without exiting the command window. In other words, it leaves the command window open after your java process exits so you can review any output. the | is a pipe operator, it passes the output of the java command as input to the exit command.

Upvotes: 0

Beau Grantham
Beau Grantham

Reputation: 3456

The double pipe (||) is used to conditionally execute a command. The command to the right is only executed if the command to the left returns an error level greater than zero.

Upvotes: 1

Related Questions