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

请考虑使用文件句柄而不是反引号从其他来源捕获标准输出。您将能够收集错误。

#!/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 回答