2

I love the pipe to feed long text output into less (or more) to make it more readable. It's only on Ubuntu that i observed a uncommon behavior: Sometimes in less keystrokes are not processed immediately. It's like i have to "confirm" them with <ENTER>. For example less opens, text is displayed, i hit <SPACE> (nothing happens), i hit <ENTER> (page scrolls down now). This is very annoying, as it makes less practically unusable because the also messes up the terminal output.

It doesn't happen for all piped commands. One example is:

php --rc PDO | less

I've never seen this happen on any other Linux distribution.

1 Answers1

3

I've been battling with this problem all afternoon and, after finding this question and reading several manpages, had a bit of a brainwave. It turns out that redirecting STDIN to /dev/null acts as a workaround and returns "normal" functionality to less:

php --rc PDO < /dev/null | less

or

cat /dev/null | php --rc PDO | less

It is, of course, a horrible kludge of a workaround, and I don't have nearly enough knowledge of pipes and stream redirection in Bash to really understand what causes the problem or why this fixes it, but I figured that posting this was better than leaving this question entirely unanswered. Hopefully someone more knowledgeable than myself will be able to shed some light on this - ideally with a more realistic fix.

My only guess is that php is receiving STDIN instead of less when you type commands into less, but I'm baffled as to why this behaviour is only seen in Ubuntu (I have confirmed that php --rc PDO | less works fine in Sabayon, CentOS and Debian, while breaking on several different Ubuntu installs, including those updated to 11.10).

Updating to include some relevant search results I've found. Turns out it's a problem with Ubuntu's build of php-cli, so it shouldn't affect any other commands.

  • Signed up here merely to say thank you! I'd been having trouble with less misbehaving while receiving data on a pipe; but working fine if I instead dumped the output to a file and then ran less on it. Redirecting STDIN to /dev/null as you said fixed the problem for me and now I can happily pipe again :) – zenzelezz Dec 14 '11 at 10:47