Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-24 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found