in reply to Re: Constructing STDIN for an external progam
in thread Constructing STDIN for an external progam

To build on Ovid's response, this should do what you want:
use strict; my $cmdout = join " ", "perl printout.pl", @ARGV; open OUT, "|$cmdout" or die "Cannot run $cmdout: $!\n"; while (<STDIN>) { s/essage/assage/sg; print OUT $_ or die "Error writing to $cmdout: $!\n"; } close STDIN; close OUT or die "Error closing $cmdout: $!\n";

Replies are listed 'Best First'.
Re^3: Constructing STDIN for an external progam
by ikegami (Patriarch) on Sep 11, 2006 at 17:27 UTC
    What if one of the args was two words? or it's? Your code won't work in those everyday situations, nevermind the security implications. You've invoking the shell without quoting and escaping your command. Use IPC::Open3, IPC::Run or IPC::Run3 to avoid having to do so.