<commit_before><commit_msg>hooks up two processes, 2nd of which has one line of output per line of input, expected by the first, which starts off the communication<commit_after>#!/usr/bin/perl -w
#hooks up two processes, 2nd of which has one line of output per line of input, expected by the first, which starts off the communication

# if you don't know how to fork/exec in a C program, this could be helpful under limited cirmustances (would be ok to liaise with sentserver)

use strict;
use IPC::Open2;
$,=' ';
my $quiet=$ENV{QUIET};
sub info {
    print STDERR @_ unless $quiet;
}

my @c1;
do {
    push @c1,shift
} while $c1[$#c1] ne '--';
pop @c1;
my @c2=@ARGV;
(scalar @c1 && scalar @c2) || die "usage: $0 cmd1 args -- cmd2 args; hooks up two processes, 2nd of which has one line of output per line of input, expected by the first, which starts off the communication.  crosses stdin/stderr of cmd1 and cmd2 line by line (both must flush on newline and output.  cmd1 initiates the conversation (sends the first line).  QUIET env var suppresses debugging output.";
info("1 cmd:",@c1,"\n");
info("2 cmd:",@c2,"\n");
my ($R1,$W1,$R2,$W2);
my $c1p=open2($R1,$W1,@c1); # Open2 R W backward from Open3.
my $c2p=open2($R2,$W2,@c2);
select $W2;
$|=1;
while(<$R1>) {
    info("1:",$_);
    print $_;
    $_=<$R2>;
    last unless defined $_;
    info("2:",$_);
    print $W1 $_;
}
{'fraction_non_alphanumeric': 0.140159767610748, 'fraction_numerical': 0.032679738562091505, 'mean_word_length': 4.141791044776119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6473308', 'n_tokens_mistral': 496, 'n_tokens_neox': 485, 'n_words': 195}