cURL / Mailing Lists / curl-library / Single Mail

curl-library

How to filter cURL stderr output but keep the progress meter output?

From: Daniele Severi <jm_at_severi.me.uk>
Date: Mon, 9 Dec 2013 15:54:08 +0000

Hi all,

I am new to cURL and I would like to filter and replace the text of
cURL errors with a custom message and this script piping to sed works:

URL=""
curl --create-dirs -o /home/user/test.dat $URL |& sed 's/curl/Custom message/g'

This is the output I get:

Custom message: no URL specified!
Custom message: try 'Custom message --help' or 'Custom message
--manual' for more information

However, when there are no errors and cURL is downloading the file I
don't get anymore the progress meter which instead I want to display.

Current output:

This is the output I get with pipe and sed when there are no errors,
notice that the progress meter is missing

URL="http_address"
curl --create-dirs -o /home/user/test.dat $URL |& sed 's/curl/Custom error/g'

  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

Desired output

This is the output obtained by commenting out pipe and sed when there
are no errors, notice that the progress meter is shown:

URL="http_address"
curl --create-dirs -o /home/user/test.dat $URL #|& sed 's/curl/Custom error/g'

  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 12980 0 12980 0 0 711k 0 --:--:-- --:--:-- --:--:-- 0

How can I filter the cURL error messages but still get my desired
output with the progress meter?

I have searched forums and tried several solutions but nothing seems
to work. As soon as you sed or grep cURL stderr the progress meter is
not shown anymore. Also, in general the questions asked in the forums
are about how to display error messages only and not to display the
progress meter, instead I want to achieve the opposite.

Many thanks for your help.

Dan
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-12-09