[San-Diego-pm] Module idea for input/output multiplexing

Emile Aben emileaben at gmail.com
Tue Dec 12 07:18:41 PST 2006


On 12/11/06, Menolly <menolly at mib.org> wrote:
> So...a cross-platform tee, basically?

yep, except 'tee' works with files as output.
Btw. using 'tee' combined with fifo's (I think that was Bob's idea), seems
to work nicely in shell:
----
#!/usr/bin/env bash
FIFO1="/tmp/fifo.$$.1"
FIFO2="/tmp/fifo.$$.2"

mkfifo $FIFO1
mkfifo $FIFO2

( cat $0 | tee $FIFO1 $FIFO2 > /dev/null )&
( openssl md5 < $FIFO1 | xargs echo md5:  )&
( wc -l < $FIFO2 | xargs echo wordcount: )&

wait;

rm $FIFO1
rm $FIFO2
------

Emile


>
> On Mon, 11 Dec 2006, Emile Aben wrote:
>
> > Hi,
> >
> > Module idea from discussion at the meeting tonight:
> > A module that hooks up stdout from one process with the stdin of
> > several other processes,
> > or maybe more generic: Something that reads from a filehandle and
> > writes that output to
> > several other filehandles.
> >
> > Simple example of use:
> > reading a gzipped file from disk, and calculating the md5 (using md5,
> > md5sum or 'openssl md5' command, depending on your OS) and linecount
> > (wc -l) **
> >
> > I've looked into IPC::Run a bit, and IPC::Run might be able to do
> > something like this, but
> > the best I've been able to come up with this far doesn't work:
> > ----
> > #!/usr/bin/env perl
> > use Carp;
> > use strict;
> > use warnings;
> > use IPC::Run qw(run);
> >
> > my $cat_cmd = ['cat'];
> > my $md5_cmd = ['/usr/bin/openssl','md5'];
> > my $wc_cmd = ['wc','-l'];
> >
> > my $md5_out = undef;
> > my $wc_out = undef;
> >
> > run($cat_cmd,'<',"$0", '>&3', '>&4',
> >  '3>pipe', $md5_cmd, '>', \$md5_out,
> >  '4>pipe', $wc_cmd,   '>', \$wc_out);
> >
> > print "linecount: $wc_out\n";
> > ---
> > which produces errors:
> > Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.3/IPC/Run/IO.pm line 329.
> > Not a GLOB reference at /usr/lib/perl5/site_perl/5.8.3/IPC/Run/IO.pm line 329.
> >
> > or under perl -d:
> >        IPC::Run::start('ARRAY(0x98ee6a8)','<','./ipcrun.pl','>&3','>&4','3>pipe','ARRAY(0x98ee714)','>','SCALAR(0x97efce0)',...)
> > called at /usr/lib/perl5/site_perl/5.8.3/IPC/Run.pm line 1434
> >     IPC::Run::run('ARRAY(0x98ee6a8)','<','./ipcrun.pl','>&3','>&4','3>pipe','ARRAY(0x98ee714)','>','SCALAR(0x97efce0)',...)
> > called at ./ipcrun.pl line 14
> >
> > that's enough for me tonight.
> >
> > Emile
> >
> >
> > ** both calculating md5 and linecount can be done in perl as well of
> > course, but that's not the point here
> > _______________________________________________
> > San-Diego-pm mailing list
> > San-Diego-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/san-diego-pm
> >
>
> --
> menolly at mib.org                    http://www.livejournal.com/~nolly/
>
> On that day, many will say to me, "Lord, Lord, did we not prophesy in
> your name, and cast out demons in your name, and do many mighty works
> in your name?" And then will I declare to them, "I never knew you;
> depart from me you evildoers." -- Matt 7:20-23, RSV
>


More information about the San-Diego-pm mailing list