0

昨日、Pidgin 2.10.9 用の perl プラグイン スクリプトを作成し、Windows 7 で実行し、Strawberry Perl 5.10.1.5 を使用しました。

基本的に、IM を受信すると、バックティックを使用してコンソール アプリケーション (.NET で記述) を呼び出し、コンソール出力を送信者に IM として返します。

今朝再起動する必要がありましたが、再起動してから動作しなくなりました。

そこで、バックティックを「キャプチャ」を使用するように変更しました。それもうまくいきませんでしたが、少なくとも次のエラーが発生しました。

(15:00:33) Plugin: Error: Error in IPC::System::Simple plumbing: "Can't dup STDOUT" - "Bad file descriptor" at (eval 12) line 53

昨日から今日までに何が変わったのかわからないので、エラーの原因を誰か知っているかどうか疑問に思いましたか?

ありがとう

編集:コードを追加すると思った

use Purple;
#use IPC::System::Simple qw(system systemx capture capturex);
use IPC::System::Simple qw(capture capturex);

%PLUGIN_INFO = (
    perl_api_version => 2,
    name => "PlugIn",
    version => "0.1",
    summary => "AutoResp",
    description => "PlugIn",
    author => "Mark Watkin",
    url => "http://",
    load => "plugin_load",
    unload => "plugin_unload"
);

sub plugin_init {
    return %PLUGIN_INFO;
}
sub plugin_load {
    my $plugin = shift;
    Purple::Debug::info("PlugIn", "plugin_load()\n");

    $data = "";
    $conversation_handle = Purple::Conversations::get_handle();
    Purple::Signal::connect($conversation_handle, "received-im-msg", $plugin, \&signal_chat_callback, $data);
}
sub plugin_unload {
    my $plugin = shift;
    Purple::Debug::info("PlugIn", "plugin_unload()\n");
}

sub signal_chat_callback {
    # The signal data and the user data come in as arguments
    my ($account, $sender, $message, $conv, $flags) = @_;

    Purple::Debug::info("PlugIn", "Account Alias \"" . $account->get_alias() . "\"\n");
    if( $account->get_alias() eq "PlugIn" )
    {
        Purple::Debug::info("PlugIn", "Request: \"" . $message . "\"\n");

        if(!$conv)
        {
            Purple::Debug::info("PlugIn", "No conversation\n");
            $conv = Purple::Conversation->new(1, $account, $sender);
        }
        $im = $conv->get_im_data();
        $im->send( "One moment please..." );

        my $query = "";
#       eval {
#           $query = capture("\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\" \"" . $message . "\"");
#           #$query = capture("\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\"", "\"" . $message . "\"");
#           #my $query = capture("D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe");
#           #my $query = `\"D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe\" \"$message\"`;
#           #my $query = `dir /b`;
#       };
#       if( $@ )
#       {
#           Purple::Debug::info("PlugIn", "Error: " . $@ . "\n");
#       }

        Purple::Debug::info("PlugIn", "Query: " . $query . "\n");
        open ( my $fh, "-|", "D:\\SourceCode\\PlugInNET\\bin\\Debug\\PlugInNET.exe \"$message\"" ) or die "Cannot run free, $ERRNO";
        while (<$fh>)
        {
             Purple::Debug::info("PlugIn", "Read: Line " . $_ . "\n");
             $query = $query . $_ . "\n";
        }
        close $fh;
        Purple::Debug::info("PlugIn", "Query: " . $query . "\n");

        if( $query eq "" )
        {
            $im->send( "I'm sorry, my brain doesn't seem to be functioning at the moment" );
        } else {
            @msgs = split(/-----------\n/, $query);
            foreach( @msgs )
            {
                Purple::Debug::info("PlugIn", "Result Msg: \"" . $_ . "\"\n");
                $im->send( "<BODY>" . $_ . "</BODY>" );
            }
        }
    }
}

計画は、パスが適切に機能するようになったら、パスを修正することでした

4

1 に答える 1

0

バッククォートの代わりにファイル ハンドルを使用して、別のソースから stdout をキャプチャすることを検討してください。エラーを収集できます。

#!/usr/bin/perl

use strict;
use warnings;
use English;

# No taint protection in this example
open ( my $fh, '-|', '/usr/bin/free' ) or die "Cannot run free, $ERRNO";
while (<$fh>)
{
   print;
}
close $fh;
于 2014-06-12T14:46:16.917 に答える