Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How to find out if it is 32bit or 64bit windows?

by Anonymous Monk
on Jun 22, 2011 at 04:49 UTC ( [id://910853]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I need to get the bitness of Windows OS on which my program runs.
I tries with Sys::Info but it doesn't yield the desired result. Here is the code I use.
use Sys::Info; my $info = Sys::Info->new; my $os = $info->os; printf "%s (%s bit)\n", $os->name(long => 1), $os->bitness;
Is there any other method that gives bit of the OS?
Thanks,

Replies are listed 'Best First'.
Re: How to find out if it is 32bit or 64bit windows?
by Khen1950fx (Canon) on Jun 22, 2011 at 06:42 UTC
    If you're not getting the desired result, then I think that you might have a dependency problem. First, check to see if Sys::Info::Driver::Windows::OS is installed. Better yet, run this script to make sure that everything's installed and uptodate.
    #!perl use strict; use warnings; use CPAN; CPAN::Shell->install( "Params::Check", "Module::CoreList", "version", "Module::Load", "Locale::Maketext::Simple", "IPC::Cmd", "ExtUtils::CBuilder", "Config::General", "Win32API::Registry", "Win::TieRegistry", "Win32::OLE", "Win32API::Net", "Scalar::Util", "File::Spec", "File::Temp", "Exporter", "Capture::Tiny", "Sys::Info::Base", "Test::Sys::Info", "Test::Harness", "Test::More", "Sys::Info::Driver::Unknown", "Sys::Info::Driver::Windows::OS");
    Then try this:
    #!perl use strict; use warnings; use Sys::Info; use Sys::Info::Constants qw( :device_cpu ); my $info = Sys::Info->new; my $cpu = $info->device( 'CPU' ); printf "%s(%s bit)\n", scalar $cpu->identify, $cpu->bitness;
      Thanks, it works now.

        Are you sure? It seems to me it's reporting the CPU bitness, not the OS bitness. When I run your original test it still reports bitness as '0'.

        I may be wrong but I don't believe it's safe to assume that CPU bitness == OS bitness.


        Dave

Re: How to find out if it is 32bit or 64bit windows?
by BrowserUk (Patriarch) on Jun 22, 2011 at 09:53 UTC

    This will tell you whether you are running under a 32 or 64-bit version of Perl, which is often more salient information:

    C:\test>\perl32\bin\perl -MConfig -le"print $Config{ptrsize}" 4 C:\test>\perl64\bin\perl -MConfig -le"print $Config{ptrsize}" 8

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      I read your post and re-read the Config docs before replying here, and just want to try to understand a little better.

      You stated that $Config{ptrsize} contains the pointer size of the version of Perl. The Config documentation supports this.

      But since a 32 bit Perl can run within a 64 bit Windows environment, how can he be sure his OS version is 64 bit?

      For example, if he's using 32 bit Perl on a 64 bit windows, wouldn't this method report 32 bit?

      It may not make any difference for his given application. Maybe it's enough to know that he's on 32 bit Perl. But what if the Perl script is making a decision as to whether to install a 32 bit version of some compiled program, or a 64 bit version? The decision wouldn't be guaranteed to be accurate if his basis for deciding is what features Perl was compiled with.

      I could be totally wrong, and am just seeking clarification.


      Dave

        That's why I said: , which is often more salient information.

        Which piece of information is the more salient depends entirely upon the OPs purpose. And until and unless he clarifies that we can never reach a conclusion as to which is the "right answer" to his question. But we've given him ways of determining both, so he can choose for himself.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

      That is the long version of how you can see that info :)

      C:\Users\Tux>perl -V:ptrsize ptrsize='4'; C:\Users\Tux>perl -V:ivsize ivsize='4'; C:\Users\Tux>perl -V:nvsize nvsize='8'; C:\Users\Tux>

      Note that ptrsize shows the size of the pointers. The length 8 indicates 64bit pointers. But even on 32bit perl installations, you can have 64bit integers: when perl was built with -Duse64bitint, and long doubles: when perl was built with -Duselongdouble.

      To solve a problem that needs native huge numbers that do not fit in 32bit integers, having a perl that supports 64bit integers is often enough. Here's such a perl on a 32bit Linux with both

      tux > perl -V:ptrsize ptrsize='4'; tux > perl -V:ivsize ivsize='8'; tux > perl -V:nvsize nvsize='12'; tux >

      compare that to a build without -Duselongdouble on the same machine:

      tux > perl5.8.8 -V:ptrsize ptrsize='4'; tux > perl5.8.8 -V:ivsize ivsize='8'; tux > perl5.8.8 -V:nvsize nvsize='8'; tux >

      and this is on 64bit Linux:

      tux > perl -V:ptrsize ptrsize='8'; tux > perl -V:ivsize ivsize='8'; tux > perl -V:nvsize nvsize='16'; tux >

      to complete this info story, -V: accepts perl regular expressions:

      $ perl -V:.*size charsize='1'; d_chsize='undef'; d_malloc_good_size='undef'; d_malloc_size='undef'; doublesize='8'; fpossize='16'; gidsize='4'; i16size='2'; i32size='4'; i64size='8'; i8size='1'; intsize='4'; ivsize='8'; longdblsize='16'; longlongsize='8'; longsize='8'; lseeksize='8'; nvsize='16'; ptrsize='8'; shortsize='2'; sig_size='69'; sizesize='8'; u16size='2'; u32size='4'; u64size='8'; u8size='1'; uidsize='4'; uvsize='8'; $

      Enjoy, Have FUN! H.Merijn
        That is the long version of how you can see that info :)

        Well yeah, but the "short version" isn't much use inside a program.

        For the rest.

        1. I know. The OP may not, be he also may not notice replies to me;
        2. when the OP asks about bits I think you can do no more than take him at his word.

          Generally, when people are concerned with the size of integers or numbers, they ask about them, not bits.

        nvsize='12';

        96-bit reals? I've encountered 32-bit, 64-bit, 80-bit and 128-bit, but never 96-bit. There isn't even an IEEE standard for those is there?

        Googling for "96-bit reals" turned up exactly 3 hits.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: How to find out if it is 32bit or 64bit windows?
by ajose (Acolyte) on Jun 28, 2011 at 14:22 UTC
    There is a Environment variable "PROCESSOR_ARCHITECTURE". You can use this to identify 32 bit and 64 bit CPUs.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://910853]
Approved by davido
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found