I am running a PHP script at the command line and piping the output through 

    ./myScript | less

Since less is an interactive program it puts the terminal into 'raw' mode so
that it can read characters one at a time. However, when I do the above I find
that the commands that I type to less are echoed back to me and not acted on
until I type <RETURN>. This is not as it should be.

The sript is not doing anything really clever, just looking at a few files and
printing out directory contents, time stamps, ...

If I run the script under strace I see:

    ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo 
...}) = 0
    ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0

I can get it to not do this by connect stdout to /dev/null:

    ./myScript > /dev/null | less

another way of getting it to work is (and this shows that it really is PHP that
is messing the tty modes):

    ./myScript > /dev/null | (sleep 10;less)

However: PHP should not set the terminal to cooked mode in the first place

Is there any way in which I can get PHP to not do this ?


I am running PHP 5.3.3 on CentOS 6.

Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
#include <std_disclaimer.h>

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to