Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get less or more to recognize keystrokes when piping from a cli php script?

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 ;-)

like image 878
Michiel Avatar asked Mar 08 '11 21:03

Michiel


2 Answers

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.

like image 153
Chris Avatar answered Nov 15 '22 21:11

Chris


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

like image 43
PJ Eby Avatar answered Nov 15 '22 22:11

PJ Eby