如何确定使用Perl的Windows操作系统的位数? [英] How can I determine the bitness of the OS using Perl on Windows?

查看:293
本文介绍了如何确定使用Perl的Windows操作系统的位数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Perl,我怎么能确定在32位Windows或我的程序是否正在运行64位的Windows?

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

有没有可用的API?

我能想到的几个选项。

  1. 查了一些Windows文件的PE_HEADER(例如: C:\ WINDOWS \ explorer.exe的) - 也许我可以使用细节<一个href="http://stackoverflow.com/questions/495244/how-can-i-test-a-windows-dll-to-determine-if-it-is-32bit-or-64bit">How我可以测试一个Windows DLL,以确定它是否是32位还是64位?

  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?

检查 C的存在:\ Program Files文件(x86)的 - 如果它存在,那么它是一个64位操作系统。否则,它是32位Windows操作系统。

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.

是否有这样做什么好办法?在Perl提供任何API?

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

推荐答案

Sys系统::信息长相有前途的:

#!/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;

输出:


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

请注意,它的错误确定了我的笔记本电脑的CPU作为64位(见的英特尔®酷睿™双核&mdash处理器T2300; bug报告提交)

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

这篇关于如何确定使用Perl的Windows操作系统的位数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆