Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if my Perl script is running under Windows?

Tags:

windows

perl

What is the best way to programatically determine if a Perl script is executing on a Windows based system (Win9x, WinXP, Vista, Win7, etc.)?

Fill in the blanks here:

my $running_under_windows = ... ? 1 : 0;
like image 798
knorv Avatar asked Sep 14 '09 21:09

knorv


People also ask

How do I know if Perl is working on Windows?

Just open a command prompt (in Windows, just type cmd in the run dialog and press Enter. If you're on a Mac or on Linux, open a terminal window). and press Enter. If Perl is installed, you receive a message indicating its version.

Where is Perl installed Windows?

The perl.exe executable should be in "C:\Users\username\Anaconda3\Library\bin\perl.exe" where username is your Windows username. If you have neither MATLAB or Anaconda you can install any other version of Perl.


1 Answers

From perldoc 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.

like image 145
Chris Lutz Avatar answered Oct 25 '22 11:10

Chris Lutz