简体   繁体   中英

How to kill java process on windows according it's parameters

I would like to kill a process using java on windows by it's parameters. If I have an exe and I run it using "exe param1 param2 etc.." and let's say param1 is unique but exe is not, I woulk like to kill the process by param1.

How can I do that ?

I am not sure what do you mean.

If you want to kill the process in Windows by command in Java you need to type this:

Runtime.getRuntime().exec("taskkill /F <processname>.exe")

It executes the Windows command passed as the string of the method of Runtime class.

taskkill - command ends one or more tasks or processes. /F - parameter specifies process to be terminated

You could use following command to find the java process id then use taskkill to kill the process or use cygwin in windows and use linux command to kill the process hth

jps -lv | findstr "STRING"

You could use following command to find the tasklist with commandline column

wmic path win32_process get  | findstr java.exe

target process started via command line : notepad killme.txt"

for /f "tokens=1,2" %i in ('wmic path win32_process get Commandline') do (IF "%j" == "killme.txt" (taskkill /FI "IMAGENAME eq %i*"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM