Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running a script on a remote machine like this:

ssh $host "pip install -r /path/to/requirements.txt"

But the output isn't line buffered; instead of seeing one line returned at a time, all the lines (~10) are all printed at once as the connection terminates.

What's up with this? Is there any way to force them to be line buffered?

(also, to state the obvious: when I ssh into $host and run the command “manually”, the output is line buffered, as expected)

share|improve this question
up vote 34 down vote accepted

Use ssh -t ... to force a pseudo-tty allocation (which is what you get when you log in normally via ssh.)

share|improve this answer

To expand a little bit on Ryan Fox's answer: Many programs (most? - it's the default for any C program) line-buffer stdout when they're talking to a terminal, but fully buffer it otherwise. (The C standard specifies that stdout is initially fully buffered when it "can be determined not to refer to an interactive device".)

So what you're seeing is that the output of the program you're running remotely (as given to stdout) isn't line-buffered; ssh is just passing through what it gets when it gets it. (I think ssh actually does no buffering at all on its output - that would be the least magical way to make sure that the user sees what the remote program intended.)

share|improve this answer
An anonymous user suggests that stdout is fully buffered, not line buffered – Michael Mrozek Oct 3 '11 at 3:53
Dave Vandervies has told me out-of-band that he was the one who made the edit, and that it is correct (ie, stdout is initially fully buffered, not line buffered). – David Wolever Oct 3 '11 at 6:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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