代码之家  ›  专栏  ›  技术社区  ›  lexu

Perl脚本如何检测它是否在Komodo IDE中运行?

  •  4
  • lexu  · 技术社区  · 15 年前

    我发现的一种方法是通过检查 已定义($db::single) 假设Komodo是活动的,如果定义了$db::single。

    但这也可能意味着脚本的合法运行方式 Perl—D 在“独立”调试器下。

    #!/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;
    }
    

    扎科夫里亚 他的建议导致:

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

    但是还有别的办法吗?


    更新 今天我的iskomodo()程序失败了。一些调查显示,它将我的全局路径设置从“long”改为“short”(这在Windows下)。%inc哈希中没有“komodo”字符串。

    我在找替代品。

    2 回复  |  直到 10 年前
        1
  •  2
  •   zakovyrya    15 年前

    在Komodo下启动脚本时,您的%inc包含什么?很有可能加载了一些特定于Komodo的模块。 最好打印内容:

    use Data::Dumper;
    print Dumper \%INC;
    
        2
  •  2
  •   lexu    12 年前

    看起来像这样的事情更容易(让剧本知道它是在科莫多手下运行的):

    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"
    }
    

    更新(通过lexu):Komodo(7)现在将Komodo_版本放在环境中。

    推荐文章