4

One way I found is to check if the Perl Debugger is "loaded" by checking for defined($DB::single) and assuming Komodo is active, if $DB::single is defined..

But this might also mean the script is legitimately running as perl -d under the "standalone" debugger.

#!/usr/local/ActivePerl-5.10/bin/perl
use strict;
use warnings;
use feature qw/say switch/;

# detect debugger ..
SayDebugerStatus();
sub SayDebugerStatus {
   print "Debugger ";
   given ($DB::single) {
      when (undef) {
         say "not loaded.";
      }
      when (0) {
         say "loaded but inactive";
      }
      default {
         say "loaded and active";
      }
   }
   return defined($DB::single) ? 1:0;
}

zakovyrya's suggestion leads to:

if ( grep( /.*Komodo\ IDE\.app/g,  values %INC) ){
    say "Komodo is running"
} else {
   say "Komodo is not running"
};

But is there another way?


UPDATE today my isKomodo() routine failed. Some investigation showed, that IT changed my global path settings from "long" to "short" names (this is under Windows) .. there nolonger is a "KOMODO" string in the %INC hash..

I'm looking for a replacement.

Scooter
  • 6,802
  • 8
  • 41
  • 64
lexu
  • 8,766
  • 5
  • 45
  • 63
  • May I ask why you need to do this? – innaM Jul 28 '09 at 16:41
  • I want to write to the "output" window (aka StdOut) when in the IDE and to a log file when running outside. (to lazzy to do it with startup options ) – lexu Jul 28 '09 at 19:10
  • And what does "outside" mean? Manually from the shell, via cron-job, etc? – innaM Jul 28 '09 at 19:39
  • yes, "Not within Komodo is outside (Komodo)" is what I meant! – lexu Jul 28 '09 at 20:44
  • Sure. But I was thinking that you could maybe try to detect if you are run from a shell. If not, you could conclude that Komodo is doing the job. – innaM Jul 29 '09 at 07:02

2 Answers2

2

What does your %INC contain when you launch script under Komodo? There is a good chance that some Komodo-specific modules are loaded. It's better to print its content with:

use Data::Dumper;
print Dumper \%INC;
zakovyrya
  • 9,579
  • 6
  • 39
  • 28
  • +1 **that works**, see my edited question ... but since "%INC" is external (based on environment) I still hope there might be another way to detect Komodo. – lexu Jul 28 '09 at 16:36
  • 1
    You will need something external. Komodo could hardly influence something internal. – innaM Jul 28 '09 at 16:42
  • as I showed above, it already loads the debugger without my doing (kind-of) .. it might load something else that is identifiable.. – lexu Jul 28 '09 at 19:11
2

Seems like something like this is easier (for the script to know it's running under Komodo):

use Modern::Perl;
if (exists $ENV{'KOMODO_VERSION'}) {
   say "Script is running under Komodo $ENV{'KOMODO_VERSION'} !";
} else {
   say "script is not running in Komodo"
}

UPDATE(by 'lexu): KOMODO (7) now places KOMODO_VERSION in the environment

lexu
  • 8,766
  • 5
  • 45
  • 63
CARP
  • 21
  • 1
  • My guess is, that $KOMODO_VERSION is new in Komodo 6 .. and yes, using that is much easier .. – lexu Nov 19 '10 at 06:35