cmd - Batch FOR command the ECHO command only show the last line of the output -
i trying utilize command process id of programs running multiple times. when utilize next command can see 3 pid
c:\>wmic process "name='notepad.exe'" processid | findstr [0-9]
output: c:>
396
13928
20424
but when utilize in same command in command echo output of lastly pid 20424 only. trying search pid of notepad.exe(or anyother program) open , see if used in procdump command, if not want execute procdump new pid.
script
@echo on /f "tokens=1" %%x in ('wmic process "name='notepad.exe'" processid ^| findstr [0-9] ^|find /v /c "notepad.exe"') set mypid=%%x echo %mypid% :loop1 if /i %mypid% geq 0 ( /f "tokens=1" %%a in ('wmic process "name='notepad.exe'" processid ^| findstr [0-9]') set npid=%%a echo %npid% echo npid %npid% /f "tokens=8" %%b in ('wmic process "name='procdump.exe'" commandline ^| findstr %npid%') ( set dpid=%%b echo dpid %dpid% if %npid% neq %dpid% ( start /b c:\users\rv017019\downloads\procdump\procdump -c 1 -s 5 -n 5 %npid% ) ) ) goto :loop1 )
output:
c:\>for /f "tokens=1" %x in ('wmic process "name='notepad.exe'" processid | findstr [0-9] |find /v /c "note pad.exe"') set mypid=%x c:\>set mypid=3 c:\>echo 3 3 c:\>if /i 3 geq 0 ( /f "tokens=1" %a in ('wmic process "name='notepad.exe'" processid | findstr [0-9]') set npid=%a echo 20424
* can see picking lastly pid
if 20424 equ 396 (echo "you right" 20424 ) else (echo "not right" ) goto :loop1 ) c:\>set npid=396 c:\>set npid=13928 c:\>set npid=20424 20424 "not right" c:\>if /i 3 geq 0 ( /f "tokens=1" %a in ('wmic process "name='notepad.exe'" processid | findstr [0-9]') set npid=%a echo 20424 if 20424 equ 396 (echo "you right" 20424 ) else (echo "not right" ) goto :loop1 ) c:\>set npid=396 c:\>set npid=13928 c:\>set npid=20424 20424 "not right"
i want each pid , search procdump command if not there execute new procdump command.
try include echo for
statement (you have utilize delayed expansion):
setlocal enabledelayedexpansion /f "tokens=1" %%x in ('wmic process "name='notepad.exe'" processid ^| findstr [0-9] ^|find /v /c "notepad.exe"') ( set mypid=%%x echo !mypid! )
batch-file cmd
No comments:
Post a Comment