Script question (batch)

neiroatopelcc

Distinguished
Oct 3, 2006
3,078
0
20,810
Why does the first command below work from a command line, but not from inside a script? (returning 44029 from script) ; in the script I had to use the stuff further down:

wmic /output:stdout product where "name like 'Microsoft Office%'" | find "Caption" 1>nul 2>&1 && (wmic /output:stdout product where "name like 'Microsoft Office%'" call uninstall /nointeractive >>"%temp%\%prg%-debug.txt") || (dir %windir%>nul)



wmic /output:stdout product where "name like 'Microsoft Office%'" | find "Caption" 1>nul 2>&1
if not x%errorlevel%==x set wmichk=%errorlevel%
if x%wmichk%==x0 wmic /output:stdout product where "name like 'Microsoft Office%'" call uninstall /nointeractive >>"%temp%\%prg%-debug.txt"
if x%wmichk%==x1 dir "%windir%">nul


Edit: On further inspection the lower script doesn't work either - it merely doesn't return an error code, so I didn't notice.
What I found was that the following command :
wmic /output:stdout product where "name like 'Microsoft Office%'" >>"%temp%\%prg%-wmi.txt"

turns into this when processed:
wmic /output:stdout product where "name like Microsoft Officetempprg-wmi.txt"

I have absolutely no clue why. But I did notice that the first character of the next line would be 'eaten' in the initial script - despite hxd conforming nothing special present around the 0x0D0A
 
Solution
I figured it out!
The problem was the % in the query - it is interpreted by the command processor instead of by the wmic command itself - so I had to escape it by typing %% instead of %
What exactly % is meant to do and why it 'eats' not only characters that would be illigal in the 8.3 format but also the first character on the next line is beyond me though.
I figured it out!
The problem was the % in the query - it is interpreted by the command processor instead of by the wmic command itself - so I had to escape it by typing %% instead of %
What exactly % is meant to do and why it 'eats' not only characters that would be illigal in the 8.3 format but also the first character on the next line is beyond me though.
 
Solution