i've been playing with POE, how about this?

use strict; use warnings; use POE qw( Wheel::Run ); POE::Session->create( inline_states => { _start => \&_start, got_line => \&got_line, timeout => \&timeout, }, ); sub _start { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; $heap->{wheel_run} = POE::Wheel::Run->new( Program => <<_SH_, /bin/sh -c 'for i in 1 2 3 4; do echo kick; sleep 4; done; sleep 600' _SH_ StdoutEvent => 'got_line', ); $heap->{seen_input} = 0; $heap->{timeout} = 10; $heap->{start} = time; $kernel->delay_set( timeout => $heap->{timeout} ); } sub got_line { my ( $heap, $line ) = @_[ HEAP, ARG0 ]; warn sprintf "%02d line: $line$/", time - $heap->{start}; $heap->{seen_input} = 1; } sub timeout { my ( $heap, $kernel ) = @_[ HEAP, KERNEL ]; warn sprintf "%02d timeout_check$/", time - $heap->{start}; unless ( $heap->{seen_input} ) { warn "\tseems to have died$/"; $heap->{wheel_run}->kill; delete $heap->{wheel_run}; return; } warn "\tseems to still be kicking$/"; $heap->{seen_input} = 0; $kernel->delay_set( timeout => $heap->{timeout} ); } POE::Kernel->run; __END__ 00 line: kick 04 line: kick 08 line: kick 10 timeout_check seems to still be kicking 12 line: kick 20 timeout_check seems to still be kicking 30 timeout_check seems to have died

i'm sure there's a cleaner way that i haven't learned yet.


In reply to Re: Read a process output asynchronously by zengargoyle
in thread Read a process output asynchronously by redbrick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.