Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: capturing stdout of pipe

by hippo (Bishop)
on Nov 14, 2019 at 13:45 UTC ( [id://11108672]=note: print w/replies, xml ) Need Help??


in reply to capturing stdout of pipe

What is the correct way to do this with pipes.

It's an FAQ! How can I open a pipe both to and from a command?

However, in the specific case of curl, my preferred answer is: don't shell out in the first place but use a module instead. eg: LWP::UserAgent, LWP::Simple, HTTP::Tiny, Furl, Net::Curl::Easy, etc., etc.

Replies are listed 'Best First'.
Re^2: capturing stdout of pipe
by Corion (Patriarch) on Nov 14, 2019 at 19:20 UTC

    Also, for converting Curl command lines to LWP (or HTTP::Tiny), see HTTP::Request::FromCurl, or its live site at https://corion.net/curl2lwp.psgi.

    The Curl command

    curl -d '{"some":"json"}' destination

    gives

    #!perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new( 'send_te' => '0' ); my $r = HTTP::Request->new( 'POST' => 'http://destination/', [ 'Accept' => '*/*', 'Host' => 'destination:80', 'User-Agent' => 'curl/7.55.1', 'Content-Length' => '15', 'Content-Type' => 'application/x-www-form-urlencoded', ], "{\x22some\x22:\x22json\x22}" ); my $res = $ua->request( $r, ); __END__ Created from curl command line curl -d '{"some":"json"}' destination

    This should give the OP a decent starting point.

Re^2: capturing stdout of pipe
by haukex (Archbishop) on Nov 14, 2019 at 19:09 UTC
    However, in the specific case of curl, my preferred answer is: don't shell out in the first place but use a module instead.

    Yes, definitely!

    It's an FAQ! How can I open a pipe both to and from a command?

    That FAQ answer says to use IPC::Open2/3, but for my personal tastes those are a little too low-level. If one really had to do this (of which this isn't a case), I would try IPC::Run first.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-18 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found