View Full Version : How Do I know which OS I am running?
super_gunda
08-09-2007, 12:09 AM
Hi,
Is there a way for me to know which Operating System I am running using Perl?
Thanks,
R
FishMonger
08-09-2007, 12:50 AM
http://linux.die.net/man/1/perlvar
$OSNAME
$^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 Config and the -V command-line switch documented in perlrun.
In Windows platforms, $^O is not very helpful: since it is always "MSWin32", it doesn't tell the difference between 95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or Win32::GetOSVersion() (see Win32 and perlport) to distinguish between the variants.
Omnis
08-10-2007, 06:02 AM
The HTTP_USER_AGENT environment variable does reveal the OS:
$ENV{'HTTP_USER_AGENT'}
FishMonger
08-10-2007, 06:55 AM
The HTTP_USER_AGENT environment variable does reveal the OS:
$ENV{'HTTP_USER_AGENT'}
That should not and can not be relied upon for 2 reasons, 1) It only works in a cgi environment. 2) It can be manually set to whatever someone wants.
Besides that, it returns the client info not the server where the script is running.
Omnis
08-13-2007, 08:01 AM
1) It only works in a cgi environment.
Does that make such a big difference since most servers running Perl are running CGI
2) It can be manually set to whatever someone wants.
Doesn't the author have full control over the environment variables?
Besides that, it returns the client info not the server where the script is running.
I thought thats what super_gunda was after.
FishMonger
08-13-2007, 08:58 AM
Just because a server is running web services and can utilize the CGI specification, doesn't mean that a Perl script is running in a CGI environment. Even though most questions in this forum, particularly in most of the other topic areas, are directly related to web programming, this question didn't specify that the script would be running in a cgi environment.
Yes, the author of the script has full control over the environment variables, so [s]he can set them to anything, but then this question would be pointless.
Actually, "which Operating System I am running using Perl", tells me that super_gunda was asking about the server side, not the client side.
Most if not all environment variables related to the remote client that the cgi spec adds can be manually set by the remote client, which is why they can't be relied upon to have accurate info.
Omnis
08-14-2007, 05:58 AM
I'm not trying to argue any points here I'm just trying to understand :)
Is there a way for me to know which Operating System I am running using Perl?
To me that sounds like his computer but its open to interpretation and of course I could be wrong. I know with my hosting provider that the OS Specs are listed in CPANEL and you could always ask your hosting provider anyhow. I would like to know what possible use(s) you could have for obtaining what OS Perl is running on with a Perl script?
Yes, the author of the script has full control over the environment variables, so [s]he can set them to anything, but then this question would be pointless.
I know it may be pointless by why would the author set these variables if they were attempting to gather this information for their own use?
Most if not all environment variables related to the remote client that the cgi spec adds can be manually set by the remote client, which is why they can't be relied upon to have accurate info.
Who exactly is the remote client? If you mean the visitor/user how could they alter what OS, browser, etc there using?
FishMonger
08-14-2007, 06:39 AM
I would like to know what possible use(s) you could have for obtaining what OS Perl is running on with a Perl script?
To write portable code. Some tasks require calling OS specific external commands. So, instead of writing multiple versions of the script, you make a query to find out which OS you're running so you can execute the proper command with the proper path specifiers.
Who exactly is the remote client? If you mean the visitor/user how could they alter what OS, browser, etc there using?
http://search.cpan.org/~gaas/libwww-perl-5.808/lib/LWP.pm
http://search.cpan.org/~gaas/libwww-perl-5.808/lib/LWP/UserAgent.pm
KevinADC
08-14-2007, 07:24 AM
The client can also use lots of other software to remove/change all the client information sent to the server.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.