Skip to main content
added 523 characters in body
Source Link

I'd like to run a curl command and only have content written to stdout if there is an error.

When I run the command from the terminal I get this functionality by default. When I run the command from within a perl script though (``), it outputs the progress info but not any error messages.

I'm able to hide the progress info by appending the -s (--silent) flag, but I can't force errors to be displayed the way they do when ran directly from bash. The -S (--show-errors) flag seems to have no effect.

I've also tried playing with diverting the output to /etc/null, but this seems to prevent anything from being output at all.

my $curl_result = `curl -s -S -X PUT "$url" -H "$h1" -H "$h2" -H "$h3" -d "$data"`; 

Below is an example of the kind of error I'd like to look for. This one is caused by a purposefully malformed IP:

{ "code":"INVALID_RECORDS", "message":"One or more of the given records is invalid", "fields": [{ "code":"INVALID_RECORDS", "message":"Invalid [ipaddress] provided for record data, [test].", "path":"records" }], "name":"ApiError", "errors":["Invalid [ipaddress] provided for record data, [test]."] } 

I'd like to run a curl command and only have content written to stdout if there is an error.

When I run the command from the terminal I get this functionality by default. When I run the command from within a perl script though (``), it outputs the progress info but not any error messages.

I'm able to hide the progress info by appending the -s (--silent) flag, but I can't force errors to be displayed the way they do when ran directly from bash. The -S (--show-errors) flag seems to have no effect.

I've also tried playing with diverting the output to /etc/null, but this seems to prevent anything from being output at all.

my $curl_result = `curl -s -S -X PUT "$url" -H "$h1" -H "$h2" -H "$h3" -d "$data"`; 

I'd like to run a curl command and only have content written to stdout if there is an error.

When I run the command from the terminal I get this functionality by default. When I run the command from within a perl script though (``), it outputs the progress info but not any error messages.

I'm able to hide the progress info by appending the -s (--silent) flag, but I can't force errors to be displayed the way they do when ran directly from bash. The -S (--show-errors) flag seems to have no effect.

I've also tried playing with diverting the output to /etc/null, but this seems to prevent anything from being output at all.

my $curl_result = `curl -s -S -X PUT "$url" -H "$h1" -H "$h2" -H "$h3" -d "$data"`; 

Below is an example of the kind of error I'd like to look for. This one is caused by a purposefully malformed IP:

{ "code":"INVALID_RECORDS", "message":"One or more of the given records is invalid", "fields": [{ "code":"INVALID_RECORDS", "message":"Invalid [ipaddress] provided for record data, [test].", "path":"records" }], "name":"ApiError", "errors":["Invalid [ipaddress] provided for record data, [test]."] } 
Source Link

Controlling curl output on Debian

I'd like to run a curl command and only have content written to stdout if there is an error.

When I run the command from the terminal I get this functionality by default. When I run the command from within a perl script though (``), it outputs the progress info but not any error messages.

I'm able to hide the progress info by appending the -s (--silent) flag, but I can't force errors to be displayed the way they do when ran directly from bash. The -S (--show-errors) flag seems to have no effect.

I've also tried playing with diverting the output to /etc/null, but this seems to prevent anything from being output at all.

my $curl_result = `curl -s -S -X PUT "$url" -H "$h1" -H "$h2" -H "$h3" -d "$data"`;