I've got a Java application, that I startup from the command prompt using a .bat file, contents look as follows :

cls
rem Starting app
set CLASSPATH=.;.\lib\
title App1 starting
java app/StartMe

It will then startup, and print output to the command window. If I want to stop the app I have to Control + C, and type Y. This is quite annoying, as I want to start/stop in a loop and I currently have to do this manually

How can I introduce a pause of 30 seconds, and then stop the Java app?

I've tried appending exit /B to the above script, but that doesn't seem to do anything, what can I do to add a wait/sleep, and then stop the Java process?

Thanks

link|improve this question

feedback

1 Answer

up vote 1 down vote accepted

A crude way is to ping localhost and redirect the output to NUL to suppress the output.

ping localhost -n 31 >NUL

You will need to alter your script as well:

cls
rem Starting app
set CLASSPATH=.;.\lib\
title App1 starting
start java app/StartMe
ping localhost -n 31 >NUL
taskkill /F /IM java.exe

So this script will start your java app, wait for 30 seconds and kill the java process

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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