batch file - getting pid of process in windows server -
i looking script pid of java process based on commandline value of task manager. these java processes have similar commandline value differ in keyword within commandline. process can't identified image name because have same java.exe. there way? i've placed below code based on npocmaka's answer
@echo off setlocal enabledelayedexpansion set "command_line="%1"" set "command_line=!command_line:"=%%!" echo ~~!command_line!~~ /f "usebackq tokens=* delims=" %%# in ( `wmic process 'commandline "%command_line%"' /format:value` ) ( /f %%$ in ("%%#") ( set "%%$" ) ) echo %processid%
i'm using keyword in commandline identify pid. yet when execute script, wrong pid. i'm assuming returning scripts pid script may contain keyword. argument while executing script taken keyword
wmic process
need.though you'll need tricks use batch.i've used more complex command line contains quotes ,brackets,spaces, file separators.... you'll need change , set value want.
first you'll need double every backslash in command line(the script should mean).quotes can problem , need replaced %
or escaped \"
(wmic
uses wql
subset of sql
commands , %
used wildcard).another thing need process result twice for
loop rid-off unwanted special characters./format:value
can used direct declaring variable/value pairs.so here is:
@echo off setlocal enabledelayedexpansion :: !!!!!!!!! set "command_line="c:\program files (x86)\dropbox\client\dropbox.exe" /systemstartup" :: !!!!!!!! set "command_line=!command_line:\=\\!" set "command_line=!command_line:"=%%!" ::or ::set "command_line=!command_line:"=\"!" rem echo ~~!command_line!~~ /f "usebackq tokens=* delims=" %%# in ( `wmic process 'commandline^="!command_line!"' /format:value` ) ( /f %%$ in ("%%#") ( set "%%$" ) ) echo %processid%
Comments
Post a Comment