4

I have a minimal HTTP server written in python (http://pastebin.com/mjLDk7Gk) that simply answers every GET request with status 200 and body "Done".

If I do

wget "http://localhost:9001" -O - -q
Done

But if I leave out the -q:

wget "http://localhost:9001" -O - 
--2015-01-12 15:28:20--  http://localhost:9001/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:9001... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified
Saving to: ‘STDOUT’

  [<=>                                                               ] 0           --.-K/s              D
  [ <=>                                                              ] 4           --.-K/s   in 0s      

2015-01-12 15:28:20 (670 KB/s) - written to stdout [4]
#blank line here

At the end of the first "status bar" line there is a "D", it is in fact the first character of the desired output. I assume that the output is somewhere lost while refreshing the terminal. This also happens with longer response bodys.

Another observation: If I redirect the output to a file, it works again:

 wget "http://localhost:9001" -O -  > /tmp/file
 cat /tmp/file
 Done

It also happens with very wide terminals. The "status bar" is growing, but there's still only one character of the response body.

Is this a bug or a configuration fault somewhere on my side? I get identical behavior with gnome-terminal and xterm (on Ubuntu 14.04.1 LTS).

2
  • Are you sure it isn't the terminal truncating instead of wrapping the output?
    – Nifle
    Jan 12, 2015 at 14:57
  • Please see the updated answer.
    – Jasper
    Jan 12, 2015 at 15:39

1 Answer 1

4

On one hand, with -O -, you are requesting wget to write the received data in stdout, which it does without buffering. On the other hand, and unless you suppress it whith -q, wget writes progress informations in stderr.

If you don't redirect one of the streams (using > some_file), they are both displayed simultaneously by the terminal, and they don't mix well, specially since wget uses special characters to display the status bar.

What you expect is for wget to :

  1. Retrieve the data and store it somewhere, while displaying progress status
  2. Then, after everything has been retrieved, display the data.

You can do this with a temporary file :

wget "http://localhost:9001" -O /tmp/some_file && cat /tmp/some_file

You could also probably use buffer :

wget "http://localhost:9001" -O - | buffer -b 1 -s 100000
2
  • I think you mean stdout in your first sentence? Apart from that, this all makes sense.
    – Jasper
    Jan 13, 2015 at 11:07
  • you are right. answer corrected
    – bwt
    Jan 13, 2015 at 11:13

You must log in to answer this question.

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