Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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?


share|improve this question
up vote 2 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:

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


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.