Reputation: 79
I'm using following command to find out the pid for some string e.g. myname.
for /f "TOKENS=1" %a in ('wmic PROCESS where "commandline like '%myname%' and name ='java.exe'" get processid') do set myid=%a
This command returns me below o/p.
set myid=ProcessId
set myid=1928
set myid=
In the end it sets empty value to myid. How can i set the process id which is 1928?
Upvotes: 2
Views: 54
Reputation: 57282
for /f "TOKENS=* delims=" %a in ('wmic PROCESS where "commandline '%myname%' and name ='java.exe'" get processid /format:value') do (set "%a" >nul)
set proc
try like this.
Upvotes: 1
Reputation: 6042
This works for me if I put it into a bat file:
@ECHO OFF
for /f "TOKENS=1 skip=1" %%a in ('wmic PROCESS where "commandline '%myname%' and name ='java.exe'" get processid') do (
SET PID=%%a
GOTO BREAK
)
:BREAK
ECHO %PID%
The important data is stored in the 2nd output so just skip the first and exit the FOR-loop after the first iteration.
Upvotes: 0