Driving me nuts!
@echo off
setlocal enableextensions EnableDelayedExpansion
:ME
set ProcessName=cmd
set wmicmd=WMIC PATH Win32_PerfFormattedData_PerfProc_Process WHERE
NAME='%ProcessName%' GET idprocess
rem echo.%wmicmd%
for /F "tokens=1-2" %%A in ('"WMIC PATH
Win32_PerfFormattedData_PerfProc_Process WHERE NAME="cmd" Get
idProcess"') do set cPID=%%A & set cCPU=%%B
echo.!cPID!
echo.!cCPU!
REM SLEEP FOR ONE SEC
ping 1.1.1.1 -n 1 -w 1000 >NUL
goto ME
endlocal
This works to report all CMD PIDs but the variable will only be set to
the last one. What are you trying to do?
@echo off
for /F "skip=1" %%A in ('"WMIC PATH
Win32_PerfFormattedData_PerfProc_Process WHERE NAME="cmd" Get
idProcess"') do echo "%%A"& set cPID=%%A
pause
--
Regards,
Mic
Try adding the usebackq parameter to the FOR statement ...
for /F "usebackq tokens=1-2" %%A in (
'WMIC PATH Win32_PerfFormattedData_PerfProc_Process WHERE NAME="cmd"
Get idProcess'
) do set cPID=%%A & set cCPU=%%b
The FOR was having trouble interpreting the statement because of the
double quotes.
BTW, I assume you removed the cCPU part for the posting, as it is,
that part will always be empty. Actually, I can't figure out what
parameter you intend for that part, but that's not my problem, is
it ;-)
__________________
Tom Lavedas
2 ways to escape errors in 'for /f circle':
1st: set "wmicmd=WMIC ... WHERE NAME^="%ProcessName%" ..."
and
2nd: set wmicmd="WMIC ... WHERE NAME="%ProcessName%" ..."
or
for /f ... ('"%wmicmd%"') do ...
wmic process where name="cmd.exe" get processid