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.