質問

I have a batch file that I am trying to run, but I keep getting an error. I think that this question is similar to I can't get the right syntax to use WMIC in batch file, but dbenham's answer doesn't completely work in my case because I am piping to findstr. Here is a part of the batch file (the part it is hanging on):

for /F %%I in ('wmic nic where 'Manufacturer!="Microsoft" and Macaddress IS NOT NULL' get index ^| findstr /r [0-9]') do ( echo %%I )

The wmic command works just fine if you run it from cmd or it's own line of a batch file, but I cannot get it to run in the for loop. Can anyone help me out here?

Thanks, John

役に立ちましたか?

解決

Try it this way:

for /f "tokens=2 delims==" %%I in (
    'wmic nic where "manufacturer!=\"Microsoft\" and macaddress is not null" get macaddress /format:list 2^>NUL'
) do echo %%I

You have to backslash-escape your quoted stuff where your quotes are nested.

他のヒント

There is a feature in WMIC that it sometimes waits for user input.

If you replace

wmic

in your example, with

echo. ^| wmic

it will allow the command to complete

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top