SSH Output – Why It Isn’t Line Buffered

ssh

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)

Best Answer

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

Related Question