Windows + wmic + memory
cmd, memory, windows, wmic
Solution
Your FOR statement is failing because the `=` is a token delimiter and it is getting stripped by the batch parser. It will work if you escape it as `^=`.
WMIC has an unfortunate "feature" that whenever its output is piped, it includes an extra carriage return character (0x0D) at the end of each line of output, plus an extra line at the end of the output. This can cause problems with extra unwanted lines in your FOR loop. Your situation is easily solved by changing the FINDSTR to look for at least one digit instead of the absence of the header line.
To get the sum you simply use SET /A in your loop (after first initializing the SUM variable).
>set SUM=0
>for /F %i IN ('wmic process where name^="test.exe" get workingsetsize ^| findstr "[0-9]"') DO set /a SUM+=%i
However - math in Windows CMD is limited to 32bit signed integer support. Your sum could easily exceed the maximum allowed value of 2,147,483,647. You would be better off using PowerShell, or else CSCRIPT to execute a VBS or JScript program. All of those alternatives support long integers (64 bit).
Problem
I would like to sum used memory of all programs named "test.exe" in a batch script. I can use the following command to get memory usage of all the appropriate processes: ``` C:\> wmic process where name="test.exe" get workingsetsize | findstr /v "WorkingSetSize" 55758848 66174976 ``` So, I guess I would like to sum all those values together with a FOR loop. The following command would just display the i variable, but nevertheless I get the appended error. ``` C:\> for /F %i IN ('wmic process where name="test.exe" get workingsetsize ^| findstr /v "WorkingSetSize"') DO echo %i test.exe - Invalid alias verb. ``` How can I change that command to sum all the used memory together and output it and it must work in the CMD, preferably very similar to my command. Thanks