Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: curl without backticks and system() (updated x2)

by haukex (Chancellor)
on Jan 29, 2017 at 22:59 UTC ( #1180578=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # WARNING: THIS CODE HAS A SECURITY HOLE
    print "Which file to show? ";
    ...
    die "bad filename" if $f=~/\.\./; # don't allow updirs
    system("cat /sharedfiles/$f")==0
        or die "command failed, \$?=$?";
    
  2. or download this
    system("cat", "/sharedfiles/$f")==0
        or die "command failed, \$?=$?";
    # OR
    system({"cat"} "cat", "/sharedfiles/$f")==0
        or die "command failed, \$?=$?";
    
  3. or download this
    use IPC::Run3 0.047 'run3';
    my $cmd = ['cat','-nE'];
    ...
    die "run3 failed, \$?=$?" unless $?==0;
    print "# STDOUT:\n$stdout";
    print "# STDERR:\n$stderr";
    
  4. or download this
    use Capture::Tiny 'capture';
    my ($stdout, $stderr, $exit) = capture {
    ...
    die "system failed, \$?=$exit" unless $exit==0;
    print "# STDOUT:\n$stdout";
    print "# STDERR:\n$stderr";
    
  5. or download this
    use IPC::System::Simple qw/systemx capturex/;
    print "# systemx:\n";
    systemx 'echo', 'Hello,', 'World!';
    my $stdout = capturex 'echo', 'Hello,', 'World!';
    print "# capturex: $stdout";
    
  6. or download this
    $ cat lengthsum.pl 
    #!/usr/bin/env perl
    ...
    
    $ cat /usr/share/dict/words | ./lengthsum.pl 
    839677
    
  7. or download this
    use 5.008;
    my @cmd = ('cat', '/usr/share/dict/words');
    ...
    }
    close $fh or die $! ? $! : $?;
    print "$sum\n";
    
  8. or download this
    use IPC::Run qw/ run new_chunker /;
    
    ...
            $sum+=length $line;
        } or die $?;
    print "$sum\n";
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2019-12-11 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?