You are not logged in.

#1 2019-01-13 21:15:52

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

How to Capture Error Output of Curl Command

The following command (though I've replaced the sensitive API key with XXX) uses the sendgrid service to send an email.

curl --request POST --url https://api.sendgrid.com/v3/mail/send --header 'Authorization: Bearer XXX' --header 'Content-Type: application/json' --data '{"personalizations": [{"to": [{"email": "account@email.com"}]}],"from": {"email": "noreply@nodomain.com"},"subject": "Hi","content": [{"type": "text/html", "value": "Hello"}]}'

If I run it when I'm not connected to the internet, I receive the message (in my terminal emulator): "curl: (6) Could not resolve host: api.sendgrid.com". However, if I try to output this to a file, redirecting STDERR to STDOUT, the file (output.txt in the example below) never seems to receive the error message... Wondering how I can actually capture that error message. Maybe Curl is using something other than STDERR to report the error?

curl --request POST --url https://api.sendgrid.com/v3/mail/send --header 'Authorization: Bearer XXX' --header 'Content-Type: application/json' --data '{"personalizations": [{"to": [{"email": "account@email.com"}]}],"from": {"email": "noreply@nodomain.com"},"subject": "Hi","content": [{"type": "text/html", "value": "Hello"}]}' 2>&1 > output.txt

Offline

#2 2019-01-13 21:24:35

ayekat
Member
Registered: 2011-01-17
Posts: 1,589

Re: How to Capture Error Output of Curl Command

How about this?

curl ... >output.txt 2>&1

See https://www.gnu.org/software/bash/manua … tions.html for more details.


pkgshackscfgblag

Offline

Board footer

Powered by FluxBB