Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How can I check from wich OS the script is running?

by kidd (Curate)
on Jul 26, 2002 at 17:39 UTC ( #185610=perlquestion: print w/ replies, xml ) Need Help??
kidd has asked for the wisdom of the Perl Monks concerning the following question:

Hello...

Is there a way to check from wich Operating System the script is running?
I would like to know if I can do that, because Im making like a requirements-checker so the user can check if they have what they need to run my scripts...

So far I have the module checker(thanks to the monks) and now I wanted to know if I can check the OS as well...

Thanks...

Comment on How can I check from wich OS the script is running?
Re: How can I check from wich OS the script is running?
by dws (Chancellor) on Jul 26, 2002 at 17:41 UTC
    Is there a way to check from wich Operating System the script is running?

    Consult $^O

Re: How can I check from wich OS the script is running?
by RMGir (Prior) on Jul 26, 2002 at 17:42 UTC
    The $^O builtin variable will tell you.

    From perldoc perlvar:

    $^O The name of the operating system under which this copy of Perl was built, as determined during the configuration process. The value is identical to "$Config{'osname'}". See also the Config manpage and the -V command-line switch documented in the perlrun manpage.
    --
    Mike
Re: How can I check from wich OS the script is running?
by broquaint (Abbot) on Jul 26, 2002 at 17:45 UTC
    You could check the $^0 variable or Config to check out what OS compiled it
    use Config; print @Config{qw/osname osvers/}; __output__ linux2.4.2-2

    HTH

    _________
    broquaint

Re: How can I check from wich OS the script is running?
by Rex(Wrecks) (Curate) on Jul 26, 2002 at 18:02 UTC
    The $^O that others have described will get you started, and for your *nix uses will be just fine. However it will only say "Win32" for any Windows OS. To require Win NT/2K/XP you can check for the value of $ENV{OS} and make sure it is "Windows_NT". It will be empty (non-existant) for the Win9x OS's. If you want more granularity than that for Windows, you need to start grubbing through the registry.

    Note: I'm not sure how the Config solution above will work on something like ActiveState which is pretty much precompiled bins.

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      Note: I'm not sure how the Config solution above will work on something like ActiveState which is pretty much precompiled bins.

      I know: not well... That returns MSWin324.0, which is clearly not true for my platform (ActivePerl 5.6.1 on WinXP).

      "One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison
        Looks to me like [MS]Win32/4.0 is the system that AS compiled the binaries on (since Config.pm is created during compile for the purpose of recording such information). Because Win32 binaries are compatible across Windows versions this means that relying on that is misleading.

        However, the shell command 'ver' on my machine emits "Microsoft Windows 2000 [Version 5.00.2195]", so if you need more granular information about which Windows version you are running on, you might try that.

Re: How can I check from wich OS the script is running?
by gmpassos (Priest) on Jul 26, 2002 at 22:03 UTC
    Check the var $^O, like the other users are saying too.
    And check this table (from perlport):

    * Unix uname $^O $Config{'archname'} -------------------------------------------- AIX aix aix BSD/OS bsdos i386-bsdos Darwin darwin darwin dgux dgux AViiON-dgux DYNIX/ptx dynixptx i386-dynixptx FreeBSD freebsd freebsd-i386 Linux linux arm-linux Linux linux i386-linux Linux linux i586-linux Linux linux ppc-linux HP-UX hpux PA-RISC1.1 IRIX irix irix Mac OS X darwin darwin MachTen PPC machten powerpc-machten NeXT 3 next next-fat NeXT 4 next OPENSTEP-Mach openbsd openbsd i386-openbsd OSF1 dec_osf alpha-dec_osf reliantunix-n svr4 RM400-svr4 SCO_SV sco_sv i386-sco_sv SINIX-N svr4 RM400-svr4 sn4609 unicos CRAY_C90-unicos sn6521 unicosmk t3e-unicosmk sn9617 unicos CRAY_J90-unicos SunOS solaris sun4-solaris SunOS solaris i86pc-solaris SunOS4 sunos sun4-sunos * DOS OS $^O $Config{archname} ID Version -------------------------------------------------------- MS-DOS dos ? PC-DOS dos ? OS/2 os2 ? Windows 3.1 ? ? 0 3 01 Windows 95 MSWin32 MSWin32-x86 1 4 00 Windows 98 MSWin32 MSWin32-x86 1 4 10 Windows ME MSWin32 MSWin32-x86 1 ? Windows NT MSWin32 MSWin32-x86 2 4 xx Windows NT MSWin32 MSWin32-ALPHA 2 4 xx Windows NT MSWin32 MSWin32-ppc 2 4 xx Windows 2000 MSWin32 MSWin32-x86 2 5 xx Windows XP MSWin32 MSWin32-x86 2 ? Windows CE MSWin32 ? 3 Cygwin cygwin ? * EBCDIC Platforms uname $^O $Config{'archname'} -------------------------------------------- OS/390 os390 os390 OS400 os400 os400 POSIX-BC posix-bc BS2000-posix-bc VM/ESA vmesa vmesa * Other perls OS $^O $Config{'archname'} ------------------------------------------ Amiga DOS amigaos m68k-amigos BeOS beos MPE/iX mpeix PA-RISC1.1


    "The creativity is the expression of the liberty".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://185610]
Approved by RMGir
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-07-10 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (206 votes), past polls