note 78231 added to function.posix-isatty
| From: | AlexKocharin at osu1 dot php dot net | Date: | Wed, 03 Oct 2007 18:06:42 +0000 |
| Subject: | note 78231 added to function.posix-isatty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131047@lists.php.net to get a copy of this message | ||
I have found this note somewhere in a http://www.phpforumz.info/, and it benefits me...
I've found that, at least in recentish versions of PHP (tested 5.1.6 and 5.2.0), using STDIN
or STDOUT produces a warning on Linux if you really do have a tty:
$ php -r 'echo posix_isatty(STDOUT) ? "tty\n" : "pipe\n";'
PHP Warning: posix_isatty(): cannot seek on a pipe in Command line code on ine 1
tty
$ php -r 'echo posix_isatty(STDOUT) ? "tty\n" : "pipe\n";' | cat
pipe
No such warning is displayed on Mac OS X so this may be quirky Linux-specific behavior. You can work
around this by using the direct file descriptor numbers, which are theoretically standard: 0 for
stdin, 1 for stdout, 2 for stderr:
$ php -r 'echo posix_isatty(1) ? "tty\n" : "pipe\n";'
tty
$ php -r 'echo posix_isatty(1) ? "tty\n" : "pipe\n";' | cat
pipe
----
Server IP: 195.54.192.44
Probable Submitter: 193.124.208.85 (proxied: 193.124.208.114)
----
Manual Page -- http://www.php.net/manual/en/function.posix-isatty.php
Edit -- https://master.php.net/note/edit/78231
Del: integrated -- https://master.php.net/note/delete/78231/integrated
Del: useless -- https://master.php.net/note/delete/78231/useless
Del: bad code -- https://master.php.net/note/delete/78231/bad+code
Del: spam -- https://master.php.net/note/delete/78231/spam
Del: non-english -- https://master.php.net/note/delete/78231/non-english
Del: in docs -- https://master.php.net/note/delete/78231/in+docs
Del: other reasons-- https://master.php.net/note/delete/78231
Reject -- https://master.php.net/note/reject/78231
Search -- https://master.php.net/manage/user-notes.php