Hi, you didn't supply sample input or output, or describe what the external program does, so the following is untested, but here's something to try using MCE.

#!/usr/bin/env perl -w use strict; use warnings; use MCE::Loop; use Capture::Tiny 'capture_stdout'; use Text::CSV 'csv'; use Try::Tiny; use JSON; MCE::Loop::init { max_workers => 8, use_slurpio => 1 }; my $data_filename = 'all.txt'; my $fail_filename = 'failed.tsv'; my $cmd = 'cfn_nag_scan'; my @args = qw/ -o json --input-path /; my @results = mce_loop_f { my ($mce, $slurp_ref, $chunk_id) = @_; my @failures; while ( $$slurp_ref =~ /([^\n]+\n)/mg ) { my $line = $1; my $json = try { return decode_json(capture_stdout { system($cmd, @args, $ +line) }); } catch { warn "processing $line failed: $_"; return; }; next unless $json; my $failure_count = $json->{file_results}{failure_count}; push @failures, [ $json->{filename} => $failure_count ] if $fa +ilure_count; } # Gather results MCE->gather(@failures); } $data_filename; unshift @results, [qw/ Filename Failures /]; csv (in => \@results, out => $fail_filename, sep_char=> "\t"); __END__

update: added json decoding and exception handling; changed return to next (thx marioroy)

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Using Parallel::ForkManager on multiple files using backtick operators for multiple files being processed simulnaneously by 1nickt
in thread Using Parallel::ForkManager on multiple files using backtick operators for multiple files being processed simulnaneously by symgryph

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.