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/

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": "",
  "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. :(

  • curl -q localhost:8083 – Eugen Rieck Aug 30 '17 at 12:07
  • @EugenRieck it doesn't help (but even if it would, it wouldn't explain the issue) – eddyP23 Aug 30 '17 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) – Eugen Rieck Aug 30 '17 at 12:18
  • Thanks, I am happy to accept it as an answer :) @EugenRieck – eddyP23 Aug 30 '17 at 12:50

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.