How does curl print to terminal while piping

Solution 1:

There are two output streams generally available: standard output, and standard error. In practice, when running in a terminal, both send data to the terminal. > only redirects standard output, and curl prints the progress data to standard error. To suppress both, use one of:

curl ... > /dev/null 2>&1
curl ... &> /dev/null    # bash's combined redirection operator
curl -s ...    # -s, --silent: Silent or quiet mode. Don't show progress meter or error messages.

To send both to a pipe:

curl ... 2>&1 | ...
curl |& ...    # bash's combined pipe

Unless you use the |& or &> operators, all streams are redirected independently.

Also see:

  • Stack Overflow: confused about stdin, stdout and stderr?

Solution 2:

When you are using curl to open an URL, you'll get two output:

  1. The status of the curl itself.
  2. The contents of that URL.

Curl should use a way to show these two separately otherwise processing of the real output (URL's content) would be hard and I'll end up with unnecessary contents (curl's status).

So it uses stderr for its status and stdout for the content.

Using > you are redirecting the URL's content (stdout) to the /dev/null, you should actually use: 2> /dev/null instead.

Also if you want to pip both of them to the next command:

curl url |&  command

If you only want the content be piped to next command while not seeing the status:

curl 2> /dev/null | command