perl-02-uni-io.pl 544 Bytes
Newer Older
epsi sayidina's avatar
epsi sayidina committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl
# Unidirectional Pipe Example
# A pipe has a read end and a write end.

use warnings;
use strict;
use File::Basename;
use IO::Pipe;

my $dirname = dirname(__FILE__);
my $path    = "$dirname/../assets";
my $cmdin   = "conky -c $path/conky.lua";
my $cmdout  = "less"; # or dzen2

my $pipein  = IO::Pipe->new();
my $hnd_in  = $pipein->reader($cmdin);

my $pipeout = IO::Pipe->new();
epsi sayidina's avatar
epsi sayidina committed
19
my $hnd_ou  = $pipeout->writer($cmdout);
epsi sayidina's avatar
epsi sayidina committed
20 21 22 23 24 25 26 27

while(<$pipein>) {
    print $pipeout $_;
    flush $pipeout;
}
    
$pipein->close();
$pipeout->close();