[英]kill processes with pid using pipes and taskkill in windows
我是批處理腳本的新手,並試圖搜索和終止進程列表,但不確定在第二個 pipe 之后如何繼續
@echo off
wmic process where "Name like 'java%%.exe' " get Processid, Caption, Commandline | find "abc" |
在這里,我使用 WMIC 列出所有 java 進程並使用find過濾它們以在命令行中獲取具有特定單詞的 java 進程,現在我需要在找到它們后殺死這些進程。 這可以通過 taskkill 或在將其寫入文件后使用 for 循環來實現嗎? 我不想使用 call Terminate 來終止進程。 有人可以幫我弄這個嗎。 提前致謝。
這首先通過.exe 名稱查找進程,然后在了解進程 ID 后查看這些進程的命令行:
@echo off
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
set exe=winver.exe
set findcommand=foo bar
REM start example programs
start "" "%exe%" %findcommand%
start "" "%exe%" %findcommand% baz
ping -n 3 localhost>nul&rem SLEEP
for /F "tokens=2 delims==" %%A in ('wmic process where "Name like '%exe%'" get ProcessID /format:list') do for /F "tokens=1,* delims==" %%B in ('wmic process where "ProcessID like '%%A'" get commandLine /format:list') do for /F %%D in ("%%~B") do (
(echo.%%C|find /I "%findcommand%" >nul)&&call taskkill /PID %%A
)
如果命令行包含echo
不喜歡的內容,我確信有辦法打破這種情況,但批處理文件就是這樣......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.