Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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