Reputation: 3511
How can I have my Perl script detect it's running on a 64-bit Windows machine, even if it's a 32-bit perl?
Upvotes: 3
Views: 1904
Reputation: 1
my @CPUIdentifierArray = split ' ', $ENV{PROCESSOR_IDENTIFIER};
my %ArcHash = ('x86' => 32, 'AMD64' => 64, 'Intel64' => 64);
my $Arch = $ArcHash{$CPUIdentifierArray[0]};
It returns 32 or 64
Upvotes: 0
Reputation: 6279
if (($ENV{'PROCESSOR_ARCHITECTURE'} eq "AMD64") or
($ENV{'PROCESSOR_ARCHITEW6432'} eq "AMD64")) {
$arch = "win64";
} else {
$arch = "win32";
}
Reference: http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx
Upvotes: 3
Reputation: 4650
Another method, although a bit more involved, would be to check the Windows API function IsWow64Process
. An example of how to do this (in Delphi) is given in the answer to this question.
Upvotes: 1
Reputation: 3511
Thanks Ben S.
From the link in the question you linked to: msdn blog on how to dectect process bitness
Yielded the following code: print "WIN64?: $ENV{PROCESSOR_ARCHITECTURE} \n"; print "WIN64?: $ENV{PROCESSOR_ARCHITEW6432} \n";
And the following output (32 bit perl on xp64)
WIN64?: x86
WIN64?: AMD64
Seems if you're running a 32bit app on 64 bit win, you'll need to reference PROCESSOR_ARCHITEW6432.
Upvotes: 4
Reputation: 69342
See this question. You check the %PROCESSOR_ARCHITECTURE%
environment variable.
Upvotes: 6