enableOutput() public method

Enables fetching output and error output from the underlying process.
public enableOutput ( ) : Process
return Process
示例#1
0
文件: Util.php 项目: laradic/support
 public static function shell($commands, array $opts = [])
 {
     //$cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array()
     if (is_array($commands)) {
         $procs = [];
         foreach ($commands as $command) {
             $procs[] = static::shell($command, $opts);
         }
         return $procs;
     }
     $process = new Process($commands);
     $options = array_replace(['type' => 'sync', 'cwd' => null, 'env' => null, 'timeout' => 60, 'callback' => null, 'output' => true], $opts);
     $options['cwd'] !== null && $process->setWorkingDirectory($options['cwd']);
     $options['env'] !== null && $process->setEnv($options['env']);
     is_int($options['timeout']) && $process->setTimeout($options['timeout']);
     if ($options['output'] === true) {
         $process->enableOutput();
     } else {
         $process->disableOutput();
     }
     $type = $options['type'];
     if ($type === 'sync') {
         $process->run($options['callback']);
     } elseif ($type === 'async') {
         $process->start();
     }
     return $process;
 }
示例#2
0
 /**
  * @param $command
  */
 public function execute($command)
 {
     $cwd = getcwd();
     chdir($this->currentWorkingDirectory);
     $process = new Process($command);
     $process->enableOutput();
     $process->run();
     if (!$process->isSuccessful()) {
         chdir($cwd);
         throw new ProcessException($process->getErrorOutput());
     }
     chdir($cwd);
 }
示例#3
0
 /**
  * Get the current git user information. We need this to extract
  * the user name and email to put into the generated files
  * @return mixed
  */
 private function getCurrentGitUser()
 {
     $p = new Process('git config --list');
     $p->enableOutput();
     $result = [];
     try {
         $p->mustRun();
         $lines = explode("\n", trim($p->getOutput()));
         foreach ($lines as $line) {
             $ar = explode('=', trim($line));
             if (count($ar) === 2) {
                 $result[$ar[0]] = $ar[1];
             }
         }
         return $result;
     } catch (\Exception $e) {
         $user = get_current_user();
         return array('user.name' => $user, 'user.email' => $user);
     }
 }