Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How can I call backticks without shell processing?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:29 UTC ( #733=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

This is a bit tricky. Instead of writing

    @ok = `grep @opts '$search_string' @filenames`;

You have to do this:

    my @ok = ();
    if (open(GREP, "-|")) {
        while (<GREP>) {
            chomp;
            push(@ok, $_);
        }
        close GREP;
    } else {
        exec 'grep', @opts, $search_string, @filenames;
    }

Just as with system(), no shell escapes happen when you exec() a list.

There are more examples of this Safe Pipe Opens.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[danaj]: :) Thanks, I should visit more often.
[holli]: you should visit the link i posted and answer my question
[stonecolddevin]: good afternoon all
[holli]: if you know what's good for you
[holli]: hahaha
[stonecolddevin]: hey holli, long time no chat
[holli]: g'day sir
[holli]: can you believe they only did nine episodes this season? GoT that is
[holli]: here's the link for you again devin: https://hastebin. com/uhifarelir.rb

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-09-26 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (297 votes). Check out past polls.

    Notices?