1

I have a batch file that runs on Windows which calls a Java class and this Java class does something and returns either 0 or -1. Here it is:

@echo off
java -cp wcs-all-1.3.jar;scala-library.jar;health-test-1.0-SNAPSHOT.jar com.test.healthtest.ServerHealthTest localhost 9999
set exitCode=%ERRORLEVEL%
if not %exitCode% 0 goto doFail
:doFail 
  echo %exitCode%
  call ../stop
  call ../start

When I run this however, I get the following message printed on the console. My Java program actually returns -1 which means that my batch file should actually call two other batch files, but I see the following as the last line:

0 was unexpected at this time.

Any ideas as to what is wrong?

1 Answer 1

1

Here is the final working version of the batch file:

@echo off
java -cp wcs-all-1.3.jar;scala-library.jar;health-test-1.0-SNAPSHOT.jar com.test.healthtest.ServerHealthTest localhost 9000
set exitCode=%ERRORLEVEL%
if %exitCode%==0 echo "Server healthy! Not restarting"
if not %exitCode%==0 (
  call ../stop
  call ../start
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.