Greg`s Tech blog

grabbing a single line of command output

Saturday 10 of January, 2004
grabbing a single line of command output

I wrote this Windows script (batch file) to grab a single line of output from a command

set /a max=1
typeperf "\memory\Pages/sec" -f csv -sc 1 -o c:\temp\1.tmp -y
for /f "usebackq skip=1 tokens=1*" %%a in ("c:\temp\1.tmp") do (
call :onlyone %%a%%b)
goto :eof

set /a counter = NaV + 1
if /i NaV gtr NaV goto :EOF
echo %* >>c:\temp\2.tmp
goto :EOF

The for command reads the file line by lines and calls only one with parameters.
:onlyone does something (in this case echo), then increments a counter to keep track of how many it has done then returns
Next time onlyone is called the counter = max, so it returns without doing anything

Note: tried to execute typeperf from within the for command but the command must write directly to the screen on a non-line oriented mode. For could not capture the output correctly