4

I am running following command,

@echo off
cls
wmic os get osarchitecture > win.txt
for /f "skip=1" %%G IN (win.txt) do echo %%G
pause>nul

Actual output am getting is,

Echo is off

Expected output,

64

or

32

depends on user architecture..

in win.txt am getting output,

OSArchitecture  
64-bit     

But in cmd window it shows blank echo is off donno why ! please fix my code. i need only 64 or 32 in output.

3

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

| improve this answer | |
2

Here's a 1 liner that works:

IF EXIST %windir%\syswow64 ( ECHO 64 ) ELSE ( ECHO 32 )
| improve this answer | |
0

Use this:

@echo off
cls 
for "tokens=2 delims==- " %%a in ('wmic os get osarchitecture /format:value') do echo %%a 
pause >nul 
| improve this answer | |
  • 4
    This doesn't work. Error: "tokens=2 delims=- " was unexpected at this time. – DavidPostill Dec 8 '19 at 18:48
  • I forgot to add an extra delims = – Wasif Hasan Dec 9 '19 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.