eSystem
[ class tree: eSystem ] [ index: eSystem ] [ all elements ]

Source for file system.php

Documentation is available at system.php

  1. <?php
  2. /**
  3.  * Project: eSystem:: The Extended file system<br>
  4.  * File:    eSystem/system.php
  5.  *
  6.  * Sub pcakge of eSystem package. This package includes extended system
  7.  * methods.
  8.  *
  9.  * @category   System
  10.  * @package    eSystem
  11.  * @subpackage eSystem_system
  12.  * @author     JoungKyun.Kim <http://oops.org>
  13.  * @copyright  (c) 2018, OOPS.org
  14.  * @license    BSD
  15.  * @link       http://pear.oops.org/package/KSC5601
  16.  * @filesource
  17.  */
  18.  
  19. /**
  20.  * alternative sysem class that based eSystem class
  21.  *
  22.  * @package eSystem
  23.  */
  24. {
  25.     // {{{ properties
  26.     public $tmpdir = '/tmp';
  27.     public $_stdout;
  28.     public $_stderr;
  29.     public $_retint = 0;
  30.  
  31.     private $tmpname = 'eSystem_system_';
  32.     // }}}
  33.  
  34.     // {{{ function _system ($_cmd, $_out = 0)
  35.     /**
  36.      *
  37.      * Proto method of eSystem exec functions.
  38.      *
  39.      * @access public
  40.      * @return void 
  41.      * @param  string command that execute an external program and display the output
  42.      * @param  int    whether saving output message on self::$_stdout
  43.      */
  44.     function _system ($_cmd, $_out = 0) {
  45.         $_err = tempnam ($this->tmpdir, $this->tmpname);
  46.         $_cmd = $_cmd . ' 2> ' . $_err . '; echo "RET_VAL:$?"';
  47.  
  48.         $pd = popen ($_cmd, "r");
  49.  
  50.         while ( ! feof ($pd) ) {
  51.             $_r = rtrim (fgets ($pd, 1024));
  52.  
  53.             if ( preg_match ("/RET_VAL:([0-9]+)$/", $_r, $_match) ) {
  54.                 $this->_retint = $_match[1];
  55.  
  56.                 if ( ! preg_match ("/^RET_VAL/", $_r) ) {
  57.                     $_r = preg_replace ('/RET_VAL:.*/', '', $_r);
  58.                     $this->_stdout[] = $_r;
  59.  
  60.                     if ( $_out ) {
  61.                         echo $_r . "\n";
  62.                         flush ();
  63.                     }
  64.                 }
  65.                 break;
  66.             } else {
  67.                 $this->_stdout[] = $_r;
  68.  
  69.                 if ( $_out ) {
  70.                     echo $_r . "\n";
  71.                     flush ();
  72.                 }
  73.             }
  74.         }
  75.         pclose ($pd);
  76.  
  77.         if ( filesize ($_err) > 0 ) {
  78.             $this->_stderr = rtrim (file_get_contents ($_err));
  79.         }
  80.         unlink ($_err);
  81.     }
  82.     // }}}
  83. }
  84.  
  85. /*
  86.  * Local variables:
  87.  * tab-width: 4
  88.  * c-basic-offset: 4
  89.  * End:
  90.  * vim600: noet sw=4 ts=4 fdm=marker
  91.  * vim<600: noet sw=4 ts=4
  92.  */
  93. ?>

Documentation generated on Fri, 30 Aug 2024 06:11:10 +0900 by phpDocumentor 1.4.4