Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Constructing STDIN for an external progam

by Ovid (Cardinal)
on Sep 11, 2006 at 12:02 UTC ( [id://572340]=note: print w/replies, xml ) Need Help??


in reply to Constructing STDIN for an external progam

You want to read perlopentut. That should answer your questions. Specifically, I think you don't want system but instead want to open the external command with a leading pipe.

open(PRINTER, "| lpr -Plp1") || die "can't run lpr: $!"; print PRINTER "stuff\n"; close(PRINTER) || die "can't close lpr: $!";

However, you'll also want to read perlsec.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^2: Constructing STDIN for an external progam
by Thelonius (Priest) on Sep 11, 2006 at 15:24 UTC
    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";
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://572340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2025-07-12 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.