1

I am running a simple command (some Kafka related stuff):

curl localhost:8083

Its output is very simple:

root@debian:/etc/kafka# curl localhost:8083/
{"version":"0.11.0.0-cp1","commit":"6a8cf706ddc9ab6a"}root@debian:/etc/kafka#

But now, when I use utility tool jq to format json, more lines get added:

root@debian:/etc/kafka# curl localhost:8083/ | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    54  100    54    0     0   1492      0 --:--:-- --:--:-- --:--:--  1500
{
  "version": "0.11.0.0-cp1",
  "commit": "6a8cf706ddc9ab6a"
}

Same happens if I pipe it to less or cat in the expected way curl ... | less. So this has nothing to do with jq itself.

My knowledge of all the stdin, stdout, stderr, pipes (that are just joins of stdout to sdtin), file redirects > < 2>, etc.. doesn't explain this behaviour. :(

4
  • curl -q localhost:8083 Aug 30, 2017 at 12:07
  • @EugenRieck it doesn't help (but even if it would, it wouldn't explain the issue)
    – eddyP23
    Aug 30, 2017 at 12:12
  • curl checks, if stdout is a TTY or a pipe and adapts its output according to it. So to shut it up you need curl -s localhost:8083/ (-s for silent, not -q for quiet as I thought) Aug 30, 2017 at 12:18
  • Thanks, I am happy to accept it as an answer :) @EugenRieck
    – eddyP23
    Aug 30, 2017 at 12:50

1 Answer 1

3

As many UNIX tools, the output of curl depends upon what type of device stdout is attached to. In this case, piping the ourput through jq changes the type from TTY to pipe, resulting in unwanted additional output.

curl has a command-line switch -s, that silences this additional output, so running curl -s localhost:8083/ | jq shold solve the issue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .