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: Re: [Adskiy] How do I find out which system I'm running under?: Edit Log



1arryb
User

May 21, 2009, 8:18 AM


Views: 912
Re: [Adskiy] How do I find out which system I'm running under?

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)


Edit Log:
Post edited by 1arryb (User) on May 21, 2009, 8:26 AM
Post edited by 1arryb (User) on May 21, 2009, 8:26 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