eddix
eddix

Reputation: 133

How a program know its output will be redirect?

When I use cURL, I Found it seems that cURL knew whether its own output will be redirect, or be input for another program.

Following are two different command:

curl http://www.google.com/

The output will be:

<HTML><HEAD>......blah, blah......</HEAD></HTML>

But if I use redirect or pipe, cURL will print its download status.

curl http://www.google.com/ | xargs echo

the output will be leading with:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   376  100   376    0     0   2729      0 --:--:-- --:--:-- --:--:--  5295
<HTML><HEAD>......blah, blah......</HEAD></HTML>

My question is: how cURL know whether its print will be redirect?

Upvotes: 1

Views: 67

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

isatty(3) will tell you if a FD is connected to a TTY.

Upvotes: 2

Related Questions