Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

separators in tasklist command output

178 views
Skip to first unread message

Petr Laznovsky

unread,
May 8, 2011, 2:14:18 PM5/8/11
to
I am try to parse tasklist command output for mem. usage of specific
process. If process consume over 1Mb of RAM, there is space as a
thousand separator (e.g. "1 033")


for /f constructions with default (space) delimiter put this number
into one token (this means, does not handle space used as separator as
a delimiter). Also construction (if "%e" GTR "30 000") failed, in case
token %e contain string "4 300" output of condition is TRUE.

Any ideas?

L.

foxidrive

unread,
May 8, 2011, 7:14:09 PM5/8/11
to

I have some but it would help knowing what you are trying to parse, to
be able to give specific help.

You can split the text into multiple tokens and add them together into
one number.


When you use quotes this does an ascii compare.

> if "%e" GTR "30 000"

--
Regards,
Mic

Petr Laznovsky

unread,
May 9, 2011, 6:16:30 AM5/9/11
to
On 9 kvě, 01:14, foxidrive <foxidr...@gotcha.woohoo.invalid> wrote:
> On 9/05/2011 04:14, Petr Laznovsky wrote:
>
> > I am try to parse tasklist command output for mem. usage of specific
> > process. If process consume over 1Mb of RAM, there is space as a
> > thousand separator (e.g. "1 033")
>
> > for /f constructions with default (space) delimiter put this number
> > into one token (this means, does not handle space used as separator as
> > a delimiter). Also construction (if "%e" GTR "30 000") failed, in case
> > token %e contain string "4 300" output of condition is TRUE.
>
> > Any ideas?
>
> I have some but it would help knowing what you are trying to parse, to
> be able to give specific help.
>

If specific process consume over than specific amount of RAM, than
kill it and start again (restart process)

> You can split the text into multiple tokens and add them together into
> one number.

Yes, I can realize this, but I still wandering why thousand separator
space does not handled as delimiter in FOR loop.


> When you use quotes this does an ascii compare.
>
>  > if "%e" GTR "30 000"
>

you are right, my fault

L.

foxidrive

unread,
May 9, 2011, 6:48:44 AM5/9/11
to
On 9/05/2011 20:16, Petr Laznovsky wrote:
>>
>
> If specific process consume over than specific amount of RAM, than
> kill it and start again (restart process)
>

This may work is you get pslist.exe from the PStools from Microsoft.
(untested)

The 500000 is in KB

@echo off
for /f "tokens=3" %%a in (
'pslist -m 2^>nul ^|find /i "firefox"'
) do (
echo virtual ram = "%%a"
if %%a GTR 500000 taskkill /F /IM firefox.exe
)
pause

--
Regards,
Mic

foxidrive

unread,
May 9, 2011, 7:01:34 AM5/9/11
to
On 9/05/2011 20:16, Petr Laznovsky wrote:

> If specific process consume over than specific amount of RAM, than
> kill it and start again (restart process)

I added a line below to restart firefox, just for completeness sake.

This may work if you get pslist.exe from the PStools from Microsoft.
(untested)

The 500000 is in KB


@echo off
for /f "tokens=3" %%a in (
'pslist -m 2^>nul ^|find /i "firefox"'
) do (
echo virtual ram = "%%a"
if %%a GTR 500000 taskkill /F /IM firefox.exe

start "" "c:\program files\firefox\firefox.exe"
)

--
Regards,
Mic

billious

unread,
May 9, 2011, 7:33:01 AM5/9/11
to

> You can split the text into multiple tokens and add them together into
> one number.
>
>
> When you use quotes this does an ascii compare.
>
> > if "%e" GTR "30 000"
>
> --
> Regards,
> Mic

Ooh - be very careful.

That's only true for the current purpose if the strings are of equal length.

Demo:

@echo off
for %%i in (
"29 999" "31 000" 123 657 "4 000"
) do (
if "%%~i" gtr "30 000" (
echo %%~i is greater than 30 000) else (
echo %%~i is NOT greater than 30 000)
)
)


ten.n...@virgin.net

unread,
May 9, 2011, 11:50:58 AM5/9/11
to

As already asked, we need to know exactly what you are trying to do!

You can parse the memory usage for a specific process directly in tasklist
without having to output it through a for loop.

:: - - - - - START - - - - -
TASKLIST /FI "MEMUSAGE gt 1048576" /FI "IMAGENAME eq FIREFOX.EXE"
/NH|FINDSTR/BI "FIREFOX.EXE">NUL 2>&1&&(ECHO=Running High)||(ECHO=Running
Okay)
:: - - - - - -END- - - - - -

0 new messages