nsteiner has asked for the wisdom of the Perl Monks concerning the following question:

Hi all
I am trying to verify from my Perl script, whether the environment I am running in is Cygwin or Windows CMD.
I found a similar thread but didn't find an answer there.

Thanks In Advance

Replies are listed 'Best First'.
Re: Check if Cygwin or Windows CMD
by bingos (Vicar) on Jan 06, 2009 at 09:53 UTC

    Usually you can check $^O to find out what OS you are running under.

    Under ActivePerl or Strawberry Perl $^O will return MSWin32

    C:\>perl -e "print $^O, qq{\n};" MSWin32

    Under Cygwin perl $^O will return cygwin.

    $ perl -e "print $^O, qq{\n};" cygwin

    This of course becomes slightly tricky when one runs ActivePerl or Strawberry Perl under the Cygwin environment or Cygwin perl under cmd.exe

    The Cygwin environment inherits all the environment variables from the Windows environment. But it appears to set several BASH related vars:

    BASH=/cygdrive/c/GNUWin32/bin/bash BASH_ARGC=() BASH_ARGV=() BASH_LINENO=() BASH_SOURCE=() BASH_VERSINFO=([0]="3" [1]="2" [2]="39" [3]="20"[4]="release" [5]="i68 +6-pc-cygwin") BASH_VERSION='3.2.39(20)-release'

    So to check whether you are running under Cygwin you could use a combination of checking $^O and $ENV{BASH_VERSION} etc.

Re: Check if Cygwin or Windows CMD
by andreas1234567 (Vicar) on Jan 06, 2009 at 10:16 UTC
    See $OSNAME or $^O in perlvar. Be sure to read the notes for Windows platforms.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]