This is getting me all sorts of frustrated. I have reverted to trying a simple test script and external program. The external program does nothing more than print a counter and then sleep for 1 second. I cannot seem to get its output while it is executing...Here is the code for both. Any help would be GREATLY appreciated...

the "child" program:

#!/usr/bin/env perl use strict; use warnings; use 5.016; use Carp qw(cluck carp croak); my $c=1; for(1..15) { say 'COUNT: '.$c; $c++; sleep(1); }

And here is the "parent" program...again, I am open to ANY solution that works. By "works", I mean that I need the output of the child program to be printed as it comes in. For the "real" program, I will need to send a web socket message every time output is received from the child program...the output will be a progress indicator (e.g. 10% complete, 15% complete, etc.).

First, with Capture::Tiny: (no dice)

#!/usr/bin/env perl use strict; use warnings; use 5.016; use Carp qw(cluck carp croak); use Data::Dumper; use Capture::Tiny ':all'; local $| = 1; my $cmd = "/tempssd/bossert/bin/testchild.pl &"; my ($stdout, $stderr, @result) = tee { system($cmd); }; while (my $line = <$stdout>) { say 'GOT: '.$line; last if $line =~ m/^FINISHED/; }

Next, with IPC::Run: (Note, I get the STDOUT AFTER it runs...and it seems that the code ref for the stdout handling never fires.

#!/usr/bin/env perl use strict; use warnings; use 5.016; use Carp qw(cluck carp croak); use Data::Dumper; use IPC::Run qw(run); local $| = 1; my @cmd = ("/tempssd/bossert/bin/testchild.pl"); run \@cmd, '<', \undef,'>&',\&stdoutH or die "cat: $?"; sub stdoutH { my ($in) = @_; chomp $in; say 'STDOUT: '.$in; }

In reply to Re^2: capture periodic updates from external program by mabossert
in thread capture periodic updates from external program by mabossert

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.