简体   繁体   中英

Taskkill : to close a java program

I supposed to close a process (java). This process is invoked by a batch file. The batch file title is "Secondary Push"

When i double the batch file, it opens a command prompt and records the log.

-How to close the java process ?? -How to get the process id of the particular java process... using command prompt. Not by Task Manager.

Tasklist will show you the details.

@ECHO OFF
SETLOCAL
SET "underline="
SET "mypid="
FOR /f "skip=2delims=" %%u IN ('tasklist/v') DO IF NOT DEFINED underline SET underline=%%u
FOR /f "delims=" %%u IN ('tasklist/v^|find /i "GPU Client"') DO IF NOT DEFINED mypid SET mypid=%%u
:loop
IF "%underline:~0,1%"=="=" SET underline=%underline:~1%&SET mypid=%mypid:~1%&GOTO loop
FOR %%u IN (%mypid%) DO IF DEFINED underline SET mypid=%%u&SET "underline="
echo Target process ID=%mypid%
GOTO :EOF

This should get the process ID ready for TASKKILL . The string GPU Client should be replaced by a uniwue string identifying the java process that you wish to terminate, which you should be able to derive from a tasklist listing from the prompt.

 tasklist /v

The length of the underline appearing under the tasklist /v report heading varies depending on the length of the longest name of tasks currently running, so the underline line is applied to underline , the selected detail line to mypid and then the first character of each string is trimmed off until the space in the line-of- = is found.

At this time, mypid will have the taskname trimmed off, so its first token is the PID.

您可以使用TasklistTaskkill

taskkill /im java*

应该杀死Java进程。

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