8

I want to be able to use the arrow keys when i pipe output from a php cli script into less. At the moment php cli does something to the tty which can only be fixed when you execute

!stty sane

from within less, which is a right pain!

I found a reference to this problem @ http://www.php.net/manual/en/features.commandline.php#90743 but i can't seem to find an answer :-)

Any help is appreciated, although this problem ranks far below many other problems ;-)

Kevin Peno
  • 9,107
  • 1
  • 33
  • 56
Michiel
  • 133
  • 1
  • 6

3 Answers3

8

I've been searching for some tweakable to do exactly this. Right now my best workaround is:

php blah.php </dev/null | less

which has the desired effect, but is a pita to have to type. It seems that when the PHP CLI detects stdin is a tty, it puts that tty into linemode.

Chris
  • 136
  • 2
2

If you add exec('stty cbreak'); to your cli script, it fixes this. (At least, it does for me, modifying drush.php for this.)

PJ Eby
  • 8,760
  • 5
  • 23
  • 19
  • Only saw this answer just now - it looks like just the thing i'm looking for - Thanks! – Michiel Aug 24 '11 at 08:20
  • I added a few more details here: http://stackoverflow.com/a/20341430/943279 It might be a PHP bug, and I included my version info for where I had issues and where I didn't in case it really is a PHP bug. – Matthew Kolb Dec 03 '13 at 01:57
0

Another options that's slightly more readable (to me) is:

less -f <(php whatevz.php)

This is also useful when trying to pipe the output of PHP's info flag:

less -f <(php -i)
Scott Buchanan
  • 1,163
  • 1
  • 11
  • 28