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

后端 未结 5 433
悲&欢浪女
悲&欢浪女 2020-12-31 13:11

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 opt

5条回答
  •  被撕碎了的回忆
    2020-12-31 13:28

    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).

提交回复
热议问题