Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69125 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2694 invoked from network); 14 Sep 2013 11:45:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Sep 2013 11:45:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 78.32.209.33 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 78.32.209.33 freshmint.phcomp.co.uk Received: from [78.32.209.33] ([78.32.209.33:43123] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2C/02-22237-86C44325 for ; Sat, 14 Sep 2013 07:45:45 -0400 Received: from addw by mint.phcomp.co.uk with local (Exim 4.72) (envelope-from ) id 1VKoIH-0007VY-3g for internals@lists.php.net; Sat, 14 Sep 2013 12:45:41 +0100 Date: Sat, 14 Sep 2013 12:45:41 +0100 To: PHP internals Message-ID: <20130914114540.GF3919@phcomp.co.uk> Mail-Followup-To: PHP internals MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Organization: Parliament Hill Computers Ltd User-Agent: Mutt/1.5.20 (2009-12-10) Subject: PHP CLI setting cooked terminal mode From: addw@phcomp.co.uk (Alain Williams) Hi, I am running a PHP script at the command line and piping the output through less: ./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 . This is not as it should be. The sript is not doing anything clever, just generating 100 lines: for($i = 0; $i < 100; $i++) echo "i=$i\n"; 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 What is happening is that PHP is putting the terminal into cooked mode. I can get it to not do this by connecting stdin 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 ? TIA I am running PHP 5.3.3 on CentOS 6. I posted this to php-general@lists.php.net a few days ago, but did not get a sensible reply. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include