Solved Problems when enable delayed expansion in a .bat

March 7, 2012 at 14:11:24
Specs: Windows 7

Hello,

This bat works fine:

for /f "tokens=* skip=1" %%i in (
'wmic logicaldisk where mediatype^=12 get name^, freespace^, size'
) do (
echo %%i >> "C:\HDD.txt"
)

But when I enable the delayed expansion, in the same bat shows me the next error:

'wmic' is not recognized as an internal or external command, operable program or batch file.

Do you know what is the possible mistake?

Thanks in advanced.


See More: Problems when enable delayed expansion in a .bat

Report •


#1
March 7, 2012 at 15:03:24
✔ Best Answer
Works for me:
Wed 2012.03.07 18.01.48
H:\>type a.cmd
@setlocal enabledelayedexpansion
@for /f "tokens=* skip=1" %%i in (
'wmic logicaldisk where mediatype^=12 get name^, freespace^, size'
) do @(
echo %%i
)
Wed 2012.03.07 18.01.58
H:\>a
123546525696  C:    160039784448
ECHO is on.

How To Ask Questions The Smart Way


Report •

#2
March 8, 2012 at 14:18:06

With this change all work, many Thanks.


Report •

#3
March 16, 2012 at 03:04:17
I get the same error even with the revised code (on WinXP). What is special about your environment?

Report •

Related Solutions

#4
March 18, 2012 at 06:13:30
I get the same error even with the revised code
The code isn't revised at all; all I did was take out the output file to demonstrate the OP's code worked fine.

What is special about your environment?
The wmic in Vista/Win7 uses different whitespace characters compared to WinXP's version. Another reason to avoid wmic in a mixed environment, honestly.

How To Ask Questions The Smart Way


Report •


Ask Question