Edit:
Found the solution: You need to do a < /dev/null
after the PHP command:
php -r 'for ($i=0; $i<300; $i++) { print "$i\n";}' < /dev/null | less
Apparently PHP behaves differently because it still expects input from stdin
.
With the < /dev/null
you force PHP into thinking there is no further input.
Edit 2:
If you don't want to (keep) typing the < /dev/null
you can create an alias for php2
or something:
alias php2="php < /dev/null`
You can make this permanent if you add it in your ~/.bashrc
.
Now you can do:
php2 -r 'for ($i=0; $i<300; $i++) { print "$i\n";}' | less
You could alias php
to itself but then you'll never have the ability to pipe something into php
.
You could of course shorten it to p
(for less typing).
Original answer:
The bug is also present in CentOS 6.5.
A newly installed CentOS 6.5 has it too (in a VM). A ... | cat | less
does not work.
A ... > a && cat a | less
does work. Go figure.
Cursor keys also don't work in php --help | less
. They do work in python --help | less
. So it must be something in the PHP executable. I think this is a longstanding bug in PHP.
I found a reference to this bug here.
Until it is fixed you need to do a redirect:
php -r 'for ($i=0; $i<300; $i++) { print "$i\n";}' > /tmp/php.txt && cat /tmp/php.txt | less
Best Answer
This is because the number pad's Enter key sends a different command then the keyboard Enter key. You could globally re-map the key to send the normal Return/Enter command, but understand that it will effect how the key works in all the other programs too.
Here are some tips on how to remap the key in X-Windows using xmodmap, or in the console/terminal using loadkeys. You probably want to map keycode 104 ("KP_Enter") to the "Return" command.