How to find OS Architecture using batch with only numberic output?

I need only 64 or 32 in output.

Use the following batch file (GetBits.cmd):

@echo off
Setlocal EnableDelayedExpansion
rem use findstr to strip blank lines
for /f "usebackq skip=1 tokens=*" %%i in (`wmic OS get OSArchitecture ^| findstr /r /v "^$"`) do (
  set "_bits=%%i"
  rem extract first 2 characters
  set "_bits=!_bits:~0,2!"
  echo !_bits!
  )
endlocal

Example output:

F:\test>GetBits.cmd
64

F:\test>

Further Reading

  • An A-Z Index of the Windows CMD command line | SS64.com
  • Windows CMD Commands (categorized) - Windows CMD - SS64.com
  • EnableDelayedExpansion - Windows CMD - SS64.com
  • Findstr - Search for strings - Windows CMD - SS64.com
  • For /f - Loop through text - Windows CMD - SS64.com
  • variable substring - Windows CMD - SS64.com

Here's a 1 liner that works:

IF EXIST %windir%\syswow64 ( ECHO 64 ) ELSE ( ECHO 32 )