Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the bitness of the OS using Perl on Windows?

Using Perl, how can I determine whether my program is running on 32 bit Windows or 64 bit Windows?

Is there any API available?

I can think of a couple of options..

  1. Check the PE_HEADER of some windows file (eg: c:\windows\explorer.exe) - maybe I can use the details in How can I test a windows dll to determine if it is 32bit or 64bit?

  2. Check for the existence of c:\program files(x86) - if it exists then it is a 64 bit OS. Else it is a 32 bit windows OS.

Is there any good way of doing this? Any API available in Perl?

like image 229
Santhosh Avatar asked Jan 08 '10 19:01

Santhosh


2 Answers

Sys::Info looks promising:

#!/usr/bin/perl

use strict; use warnings;
use Sys::Info;

my $info = Sys::Info->new;

my $cpu = $info->device('CPU');

printf "%s (%s bit)\n", scalar $cpu->identify, $cpu->bitness;

my $os = $info->os;

printf "%s (%s bit)\n", $os->name(long => 1), $os->bitness;

Output:

C:\Temp> t
Genuine Intel(R) CPU T2300 @ 1.66GHz (64 bit)
Windows XP Service Pack 3 build 2600 (32 bit)

Note that it incorrectly identifies my laptop's CPU as being 64 bit (see Intel® Core™ Duo Processor T2300—bug report filed).

like image 126
Sinan Ünür Avatar answered Sep 21 '22 02:09

Sinan Ünür


Perhaps you can just check some environment variables:

See HOWTO: Detect Process Bitness.

like image 42
kolbyjack Avatar answered Sep 20 '22 02:09

kolbyjack