Skip to main content
added 1 character in body
Source Link
Io-oI
  • 8.3k
  • 3
  • 13
  • 41
@echo off

for /f useback^tokens^=4^delims^=^<^> %%g in (
`%__AppDir__%wbem\wmic.exe Process where "Name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId /format:xml ^| find "VALUE"
`)do set "_var=%%~g"

echo; %var%%_var%

However, the var variable is NOT being set correctly.
That's not right to say, in fact the variable takes on a value in the
1st and 2nd loop of the for output, but in the last one it removes the variable.

 SET var=ProcessId
 SET var=4964
 SET var=    // remove variable // 

The output (encodind) of wmic.exe doesn't help and generates line break when using in the simple form (get MyPizza). After a few tries with the different optional output formats (via command complement), I started to make use of /format:xml with ^| find "VALUE" to get a line of output and not have the extra spaces and/or newlines.

When copying a command|clip output and pasting it into an edit, notice the additional lines:

> wmic PROCESS where "name like '%cmd.exe%' and CommandLine like '%windows%'" get commandline|clip
  • Output pasted into a text editor:

enter image description here

I suggest that you consult this question:
WMIC command in batch outputting non UTF-8 text files

@echo off

for /f useback^tokens^=4^delims^=^<^> %%g in (
`%__AppDir__%wbem\wmic.exe Process where "Name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId /format:xml ^| find "VALUE"
`)do set "_var=%%~g"

echo; %var%

However, the var variable is NOT being set correctly.
That's not right to say, in fact the variable takes on a value in the
1st and 2nd loop of the for output, but in the last one it removes the variable.

 SET var=ProcessId
 SET var=4964
 SET var=    // remove variable // 

The output (encodind) of wmic.exe doesn't help and generates line break when using in the simple form (get MyPizza). After a few tries with the different optional output formats (via command complement), I started to make use of /format:xml with ^| find "VALUE" to get a line of output and not have the extra spaces and/or newlines.

When copying a command|clip output and pasting it into an edit, notice the additional lines:

> wmic PROCESS where "name like '%cmd.exe%' and CommandLine like '%windows%'" get commandline|clip
  • Output pasted into a text editor:

enter image description here

I suggest that you consult this question:
WMIC command in batch outputting non UTF-8 text files

@echo off

for /f useback^tokens^=4^delims^=^<^> %%g in (
`%__AppDir__%wbem\wmic.exe Process where "Name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId /format:xml ^| find "VALUE"
`)do set "_var=%%~g"

echo; %_var%

However, the var variable is NOT being set correctly.
That's not right to say, in fact the variable takes on a value in the
1st and 2nd loop of the for output, but in the last one it removes the variable.

 SET var=ProcessId
 SET var=4964
 SET var=    // remove variable // 

The output (encodind) of wmic.exe doesn't help and generates line break when using in the simple form (get MyPizza). After a few tries with the different optional output formats (via command complement), I started to make use of /format:xml with ^| find "VALUE" to get a line of output and not have the extra spaces and/or newlines.

When copying a command|clip output and pasting it into an edit, notice the additional lines:

> wmic PROCESS where "name like '%cmd.exe%' and CommandLine like '%windows%'" get commandline|clip
  • Output pasted into a text editor:

enter image description here

I suggest that you consult this question:
WMIC command in batch outputting non UTF-8 text files

Source Link
Io-oI
  • 8.3k
  • 3
  • 13
  • 41

@echo off

for /f useback^tokens^=4^delims^=^<^> %%g in (
`%__AppDir__%wbem\wmic.exe Process where "Name like '%java%' and CommandLine like '%surveyEngine%'" get ProcessId /format:xml ^| find "VALUE"
`)do set "_var=%%~g"

echo; %var%

However, the var variable is NOT being set correctly.
That's not right to say, in fact the variable takes on a value in the
1st and 2nd loop of the for output, but in the last one it removes the variable.

 SET var=ProcessId
 SET var=4964
 SET var=    // remove variable // 

The output (encodind) of wmic.exe doesn't help and generates line break when using in the simple form (get MyPizza). After a few tries with the different optional output formats (via command complement), I started to make use of /format:xml with ^| find "VALUE" to get a line of output and not have the extra spaces and/or newlines.

When copying a command|clip output and pasting it into an edit, notice the additional lines:

> wmic PROCESS where "name like '%cmd.exe%' and CommandLine like '%windows%'" get commandline|clip
  • Output pasted into a text editor:

enter image description here

I suggest that you consult this question:
WMIC command in batch outputting non UTF-8 text files