Skip to content
Advertisement

How can we stop a running java process through Windows cmd?

I am a newbie in cmd, so please allow me to ask a stupid question: How can we stop a running Java process through Windows cmd?

For example, if we start Jetty (a mini web server) with the following command:

start javaw -jar start.jar

How do we find the process and stop it later?

Obviously the following command does not work:

stop javaw -jar start.jar

Advertisement

Answer

It is rather messy but you need to do something like the following:

START "do something window" dir
FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq do something window"' ) DO SET PID=%I
ECHO %PID%
TASKKILL /PID %PID%

Found this on this page. (archived)

(This kind of thing is much easier if you have a UNIX / LINUX system … or if you run Cygwin or similar on Windows.)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement