CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How do I find out which system I'm running under?

 



Adskiy
New User

May 21, 2009, 6:35 AM

Post #1 of 5 (393 views)
How do I find out which system I'm running under? Can't Post

Please help. I need to determine the architecture of the system which the script's running. Via Perl, of course. We have HPUX-ia64, HPUX-RISK, Solaris-ix86, Solaris-sparc. I can determine the Solaris from HPUX via $^O, but how ix-86 from sparc, risk, etc? Thank you!


Adskiy
New User

May 21, 2009, 7:50 AM

Post #2 of 5 (387 views)
Re: [Adskiy] How do I find out which system I'm running under? [In reply to] Can't Post

What you think about this way?

my $byteorder = $Config{byteorder};
unless (index($byteorder,1))
{
## code for ix86 & ia64
}
else
{
## code for risk & sparc
}


In Reply To


1arryb
User

May 21, 2009, 8:18 AM

Post #3 of 5 (384 views)
Re: [Adskiy] How do I find out which system I'm running under? [In reply to] Can't Post

Hi Adskiy,

If you are running under L/Unix or Windows/cygwin:

Code
# /usr/bin/perl; 

use strict;
use warnings;

$os = `uname -o`;
$os =~ tr/\r\n//d; # Same as chomp();
$os = lc($os);
$os = 'win32' if $os eq 'cygwin';
my $arch = lc(`uname -m`);
$arch =~ tr/\r\n//d;
$arch = lc($arch);
print "I am an $arch machine running the $os operating system.\n";

Be aware that not all versions of uname report the same strings for the same thing, so this kind of code needs testing on various platforms.

If you need precise information on the Windows variant or you don't use cygwin, this won't help.

Cheers,

Larry


(This post was edited by 1arryb on May 21, 2009, 8:26 AM)


Adskiy
New User

May 21, 2009, 8:46 AM

Post #4 of 5 (381 views)
Re: [1arryb] How do I find out which system I'm running under? [In reply to] Can't Post

Yes, you are right. On solaris uname -o returns 'illegal option' and 'uname -m' returns only 'sun4u'. Threfeore, nothing happens. The code should be useful for all described platforms.


1arryb
User

May 21, 2009, 9:17 AM

Post #5 of 5 (377 views)
Re: [Adskiy] How do I find out which system I'm running under? [In reply to] Can't Post

Adskiy,

'A fair cop', as they say. I did take a look at the Sys::Info module from CPAN, but it didn't do any better (e.g., architecture info was completely unavailable. You can substitute "print "$^O" (dollar-CTRL-O) to for "uname -o" to get the OS. I was unable to find a pure-Perl method for getting the machine architecture. Perhaps others can help with that.

As I noted before, different implementations of uname have their own idiosyncracies. You may just have to suck it up and deal with them in your code. Hint: most versions of uname support the '-a' flag. You can preprocess uname -a to get a general idea of the platform and make syntax adjustments based upon what you see.

Cheers,

Larry


(This post was edited by 1arryb on May 21, 2009, 9:19 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives