开发者

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

开发者 https://www.devze.com 2023-02-15 10:21 出处:网络
I want to be able to use the arrow ke开发者_如何学编程ys 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

I want to be able to use the arrow ke开发者_如何学编程ys 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 ;-)


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消