note 22327 modified in features.commandline by nlopess
| From: | nlopess@php.net | Date: | Sun, 15 May 2005 16:32:54 +0000 |
| Subject: | note 22327 modified in features.commandline by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-89457@lists.php.net to get a copy of this message | ||
PHP 4.3 and above automatically have STDOUT, STDIN, and STDERR openned ... but < 4.3.0 do not.
This is how you make code that will work in versions previous to PHP 4.3 and future versions without
any changes:
<?php
if (version_compare(phpversion(),'4.3.0','<')) {
define('STDIN',fopen("php://stdin","r"));
define('STDOUT',fopen("php://stout","r"));
define('STDERR',fopen("php://sterr","r"));
register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STDOUT);
fclose(STDERR); return true;' ) );
}
/* get some STDIN up to 256 bytes */
$str = fgets(STDIN,256);
?>
--was--
PHP 4.3 and above automatically have STDOUT, STDIN, and STDERR openned ... but < 4.3.0 do not.
This is how you make code that will work in versions previous to PHP 4.3 and future versions without
any changes:
<?php
if (version_compare(phpversion(),'4.3.0','<')) {
define('STDIN',fopen("php://stdin","r"));
define('STDOUT',fopen("php://stout","r"));
define('STDERR',fopen("php://sterr","r"));
register_shutdown_function( create_function( '' , 'fclose(STDIN); fclose(STOUT);
fclose(STERR); return true;' ) );
}
/* get some STDIN up to 256 bytes */
$str = fgets(STDIN,256);
?>
http://php.net/manual/en/features.commandline.php