Solved If statement not working for no apparent reason

Hewlett-packard / Pavilion hpe
December 3, 2014 at 11:55:19
Specs: Windows 7 Professional, 3.6GHz 16GB
When I enter:

for /f "tokens=2 delims==" %A in ('wmic os get OSArchitecture /format:value') do set architecture=%A

in CMD, it returns:

architecture=64-bit

However, when I use it in a batch file:

for /f "tokens=2 delims==" %%A in ('wmic os get OSArchitecture /format:value') do set architecture=%%A
if /i not !architecture!==64-bit goto stop

It sends the script to the stop label, even when the architecture variable IS equal to 64-bit.

What am I doing wrong?

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner


See More: If statement not working for no apparent reason

Report •


#1
December 3, 2014 at 20:54:45
✔ Best Answer
It's that damned unicode again. F/e: after loading,
for /f "tokens=2 delims==" %%A in ('wmic os get OSArchitecture /format:value') do set architecture=%%A

try this:
echo !architecture!***
you will note that the first two characters of "64-bit" appear to be asterisks, but what you have is an embedded CR in the variable. Output the variable to a file and use EDIT:
>arch echo **!architecture!**
EDIT arch
and you will see the CR at the end of the var. content, looks like a musical note. All ya gotta do is trim that CR off your variable:

set architecture=!architecture:~0,-1!

That should fix it.
ps: interestingly, percent variables aren't thus afflicted, only exclam variables! try this:

echo !architecture!***
echo %architecture%***

message edited by nbrane


Report •

#2
December 4, 2014 at 01:51:30
I don't know if this is what you had in mind, but it seemed to fix the issue

for /f "tokens=2 delims==" %%A in ('wmic os get OSArchitecture /format:value') do set architecture=%%A
echo **!architecture!**> osa
for /f %%A in (osa) do set architecture=%%A
set architecture=!architecture:~2,-3!
if /i not !architecture!==64-bit goto stop

Thank you c:

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner


Report •

Related Solutions


Ask Question