从Pidgin插件脚本的STDOUT



昨天,我为Pidgin 2.10.9编写了一个perl插件脚本,运行在Windows 7上,使用Strawberry perl 5.10.1.5

基本上,在收到IM时,它使用反引号调用控制台应用程序(用。net编写),并将控制台输出作为IM返回给发送者。

我今天早上必须重新启动,但是自从我重新启动后,它就停止工作了。

因此,我将反勾改为使用"capture"。这也不工作,但它至少给了我这个错误:

(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 conversationn");
            $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>" );
            }
        }
    }
}

计划是一旦我让它正常工作就修复路径

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

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

相关内容

  • 没有找到相关文章

最新更新