---------- Forwarded message ----------
From: woosley. xu. <redic...@gmail.com>
Date: 2009/9/25
Subject: Re: run an interactive command using POE::Wheel?
To: Andreas Altergott <alterg...@mira-consulting.net>


Hi, Andreas,
    Thanks for your reply.
     I found if I changed the my code to

                   $_[HEAP]->{job}->put("woosley\npassword");

  just like you did, then the get_name.pl can get the username and password
correctly.

   Then I changed the code like this

            $_[HEAP]->{job}->put("woosley");
            $_[HEAP]->{job}->put("password");
It worked this time.

Still I don't know why I can not put a "\n" after each words, perldoc
POE::Wheel::Run says
*POE::Wheel::Run communicates with the child process in a line-based fashion
by default*

besides, if you write the interactive code like this:

    my $user = <STDIN>;
    chomp $user;
    $_[HEAP]->{job}->put("$user");
    my $pass = <STDIN>;
    chomp $pass;
    $_[HEAP]->{job}->put("$pass");

It won't pop up all the message from the child process until you finished
all your input. Maybe this is not the right way to do it, I am wondering
which is the way.

2009/9/25 Andreas Altergott <alterg...@mira-consulting.net>

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


-- 
Woosley.Xu
Tju->PMO->Rdps



-- 
Woosley.Xu
Tju->PMO->Rdps

Reply via email to