Comprobación del nivel de error en un archivo por lotes

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.

¿Alguna idea de lo que está mal?

preguntado el 28 de mayo de 14 a las 14:05

1 Respuestas

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
)

contestado el 28 de mayo de 14 a las 14:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.