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
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