Hi,

woosley. xu. wrote:
> Apparently I failed to get the password but get the last "\n" in the first
> input to password.  But if I got rid of "\n", the whole script just blocked.
> How can I deal with such a situation?

I didn't find the error, but I've written your application a little bit
different.  This is working for me.  Maybe it helps you to find
something.  Please let me (us on the mailing list ;-) ) know if you do.
 Sorry if I'm not of much help.  I really didn't see the mistake.
Probably it has something to do with the StdioFilter that is missing in
your code.

I'm new to POE, so I don't have any answer for you second question.

#!/usr/bin/perl
#-----------------------------------------------------------------------
# main.pl

use strict;
use warnings;

use POE qw(Wheel::Run Filter::Line);

sub _start {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    $heap->{'child'} = POE::Wheel::Run->new(
        'CloseEvent'   => 'child_close',
        'Program'      => ['perl', 'child.pl'],
        'StderrEvent'  => 'child_stderr',
        'StdoutEvent'  => 'child_stdout',
        'StdioFilter'  => POE::Filter::Line->new(),
        'StderrFilter' => POE::Filter::Line->new()
    );

    $kernel->sig_child($heap->{'child'}->PID, 'sig_chld');
    $heap->{'child'}->put("user\npw\n");
}

sub child_close {
    my ($kernel, $heap) = @_[KERNEL, HEAP];

    delete($heap->{'child'});
}

sub child_stderr {
    my $stderr = $_[ARG0];

    print("$stderr\n");
}

sub child_stdout {
    my $stdout = $_[ARG0];

    print("$stdout\n");
}

sub sig_chld {
}

POE::Session->create(
    inline_states => {
        '_start'       => \&_start,
        'child_close'  => \&child_close,
        'child_stderr' => \&child_stderr,
        'child_stdout' => \&child_stdout,
        'sig_chld'     => \&sig_chld
    }
);

POE::Kernel->run();
exit(0);

# EOF
#-----------------------------------------------------------------------

#!/usr/bin/perl
#-----------------------------------------------------------------------
# child.pl

use strict;
use warnings;

my ($user, $pw);

print("User:\n");
$user = <STDIN>;

print("Password:\n");
$pw = <STDIN>;

chomp($user);
chomp($pw);

print("Entered: $user/$pw\n");

# EOF
#-----------------------------------------------------------------------


Regards,
Andreas

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to