如何在 Windows 上使用 Perl 确定操作系统的位数? [英] How can I determine the bitness of the OS using Perl on Windows?
问题描述
使用 Perl,我如何确定我的程序是在 32 位 Windows 还是 64 位 Windows 上运行?
有可用的 API 吗?
我能想到几个选项..
检查某些 windows 文件的 PE_HEADER(例如:
c:windowsexplorer.exe
) - 也许我可以使用 我如何测试 Windows dll 以确定它是否是32位还是64位?检查
c:program files(x86)
是否存在 - 如果存在,则它是 64 位操作系统.否则它是一个 32 位 Windows 操作系统.
有什么好的办法吗?Perl 中有可用的 API 吗?
Sys::Info 看起来很有希望:
#!/usr/bin/perl使用严格;使用警告;使用系统::信息;我的 $info = Sys::Info->new;我的 $cpu = $info->device('CPU');printf "%s (%s bit)
", 标量 $cpu->identify, $cpu->bitness;我的 $os = $info->os;printf "%s (%s bit)
", $os->name(long => 1), $os->bitness;
输出:
<前>C:Temp> t正版 Intel(R) CPU T2300 @ 1.66GHz(64 位)Windows XP Service Pack 3 build 2600(32 位)请注意,它错误地将我的笔记本电脑的 CPU 识别为 64 位(请参阅 英特尔® 酷睿™ 双核处理器 T2300—已提交错误报告).
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..
Check the PE_HEADER of some windows file (eg:
c:windowsexplorer.exe
) - maybe I can use the details in How can I test a windows dll to determine if it is 32bit or 64bit?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?
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)
", scalar $cpu->identify, $cpu->bitness;
my $os = $info->os;
printf "%s (%s bit)
", $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).
这篇关于如何在 Windows 上使用 Perl 确定操作系统的位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!