Reputation: 91
I'm writing a Perl wrapper for another application.
I need to pipe STDIN and some STDOUT.
#!/usr/bin/perl -w
use strict;
use IPC::Run3 qw(run3);
my $stdout;
local $| = 1;
run3 ['node','gekko',"-b","-c","BNB-XLM-Doktor_v1-5-144-config.js"], undef, $stdout;
2018-03-18 13:50:10 (DEBUG): Available 142534
2018-03-18 13:50:10 (DEBUG): Optimal 144240
2018-03-18 13:50:10 (INFO): The database has 1707 candles missing, Figuring out which ones...
2018-03-18 13:50:11 (INFO): Gekko detected multiple dateranges in the locally stored history. Please pick the daterange you are interested in testing:
2018-03-18 13:50:11 (INFO): OPTION 1:
2018-03-18 13:50:11 (INFO): from: 2017-12-08 07:04:00
2018-03-18 13:50:11 (INFO): to: 2018-03-14 19:04:00
2018-03-18 13:50:11 (INFO): OPTION 2:
2018-03-18 13:50:11 (INFO): from: 2018-03-16 00:04:00
2018-03-18 13:50:11 (INFO): to: 2018-03-18 10:04:00
prompt: option:
OPTION 1:
from: 2017-12-08 07:04:00
to: 2018-03-14 19:04:00
OPTION 2:
from: 2018-03-16 00:04:00
to: 2018-03-18 10:04:00
prompt: option:
So STDOUT must be filtered and I haven't any idea how do this.
I tried with $stdout =~ s/....//g
but it's not working.
Remember that it must send STDIN from parent to child too after filtering STDOUT
Upvotes: 2
Views: 313
Reputation: 241908
You can specify a sub instead of a file handle for stdout, it will get each line of the output as an argument:
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Run3 qw(run3);
my $stdout;
local $| = 1;
run3 ['command'], undef, sub {
$_ = shift;
return unless /(?:OPTION \d+|from|to|option):\s+/;
s/.*INFO\):\s+//;
print
};
Upvotes: 0