9

I'm trying to run the following command in a *FOR /F in Windows' shell …

wmic process where ParentProcessId=%%PID%% get ProcessId

The = between ParentProcessId and %PID% keeps getting replaced by a space.

The result being:

for /F "usebackq" %b in (wmic process where ParentProcessId %PID% get ProcessId) do (.

How would I escape the = character?

Rohit Gupta
  • 5,096

2 Answers2

8

Try:

for /F "usebackq" %b in (`wmic process where ParentProcessId^=0 get ProcessId`) do echo %b

The “=” sign is escaped with a “^”. Also note that the wmic command itself is enclosed in “back quotes” as called for by your use of the usebackq parameter.

BillP3rd
  • 6,599
2

How would I escape this character = sign?

for /F "usebackq" %%b in (wmic process where ParentProcessId=%PID% get ProcessId) do (

There are two problems with the above:

  1. When using "usebackq" you need to put backquotes around the command to be processed by for.

  2. There needs to be quotes " around the where clause of wmic.

Use the following batch file:

@echo off
setlocal 
set PID=1188
for /F "usebackq" %%b in (`wmic process where "ParentProcessId=%PID%" get ProcessId`) do (
  echo %%b
  )
endlocal

Example output:

F:\test>test
ProcessId
2508
10100
ECHO is off.

Note:

  • The ECHO is off. line is output because wmic outputs a final blank line.

Further Reading

DavidPostill
  • 162,382