1.

Solve : Troubled by `set`?

Answer»

Hi again guys,

Am trying to count the number of "Running" counters listed in a text document.
Unfortunately I can't see where my SCRIPTING has gone so far south...

The textfile contains ...Code: [Select]SRVR-W2 Counter Running
SRVR-W8 Counter Running
SRVR-QA2 Counter Running
SRVR-W3 Counter Running
SRVR-DB2 Counter Running
SRVR-DB1 Counter Running
SRVR-DB8 Counter Running
SRVR-W1 Counter Running
SRVR-W7 Counter Running
The portion of script that is going south ...Code: [Select]:: Push 'logman query' to a text file.
logman query | findstr /C:"Counter" | findstr /V "System" > %LogmanTxt%

@echo -Collection----- -TYPE------- -Status------
For /F "tokens=1-3 delims= " %%x in (%LogmanTxt%) do (
@echo %%x %%y %%Z

if %%z==Running set /A Run=%Run%+1

)

@echo // Total Running: %Run%.
Currently returns 1.

Any help appreciated.

Cheers,
CameronAnything inside a for loop is like going down the rabbit hole.

Code: [Select]:: Push 'logman query' to a text file.
logman query | findstr /C:"Counter" | findstr /V "System" > %LogmanTxt%

@echo -Collection----- -Type------- -Status------
For /F "tokens=1-3 delims= " %%x in (%LogmanTxt%) do (
@echo %%x %%y %%z

if %%z==Running CALL set /a run=%%run%%+1


)

@echo // Total Running: %Run%.
Hello SideWinder,

Many thanks for the reply.
Unfortunately it wasn't a positive result ...Code: [Select]:: Push 'logman query' to a text file.
logman query | findstr /C:"Counter" | findstr /V "System" > %LogmanTxt%

@echo -Collection----- -Type------- -Status------
For /F "tokens=1-3 delims= " %%x in (%LogmanTxt%) do (
@echo %%x %%y %%z

if "%%z"=="Running" set /A Run=%%Run%%+1

)

@echo // Total Running: %Run%.It did return a farmiliar error during the loop.Code: [Select]-Collection----- -Type------- -Status------
SRVR-W2 Counter Running
Missing operand.
SRVR-W8 Counter Running
Missing operand.
SRVR-QA2 Counter Running
Missing operand.
SRVR-W3 Counter Running
Missing operand.
SRVR-DB2 Counter Running
Missing operand.
SRVR-DB1 Counter Running
Missing operand.
SRVR-DB8 Counter Running
Missing operand.
SRVR-W1 Counter Running
Missing operand.
SRVR-W7 Counter Running
Missing operand.
// Total Running: .Would you have an alternative to what I'm trying to do ??

Cheers,
CameronFound the solution ...

Thought about your comment regarding the loop and the last major script I wrote had issues retaining values within the FOR loop and returning the value after the FOR loop.

The solution I've found (rediscovered) ...

SETLOCAL ENABLEDELAYEDEXPANSION
...
set /A Run=0
:: Push 'logman query' to a text file.
logman query | findstr /C:"Counter" | findstr /V "System" > %LogmanTxt%

@echo -Collection----- -Type------- -Status------
For /F "tokens=1-3 delims= " %%x in (%LogmanTxt%) do (
@echo %%x %%y %%z

if "%%z"=="Running" set /A Run=!Run!+1

)

@echo // Total Running: %Run%.
...
ENDLOCAL

Works a treat. Thanks for the reminder.

Cheers,
Cameron



Discussion

No Comment Found