/**
  * Runs the process.
  *
  * @param Closure|string|array $callback A PHP callback to run whenever there is some
  *                                       output available on STDOUT or STDERR
  *
  * @return integer The exit status code
  *
  * @api
  */
 public function run($callback = null)
 {
     if (null === $this->getCommandLine()) {
         $this->setCommandLine($this->getPhpBinary());
     }
     return parent::run($callback);
 }
 public function fork(Process $children, $user_name = null, $group_name = null)
 {
     if ($this->allocateSHMPerChildren()) {
         $children->setSHMSegment(new SHMCache(uniqid('process_manager;shm_per_children' . $children->getInternalId()), $this->allocateSHMPerChildren));
     }
     pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD));
     $pid = pcntl_fork();
     // Error
     if ($pid == -1) {
         throw new RuntimeException('pcntl_fork() returned -1, are you sure you are running the script from CLI?');
     } else {
         if (!$pid) {
             if (!is_null($group_name)) {
                 if (!$this->setGroup($group_name)) {
                     throw new RuntimeException('set group_name failed. are you sure you have the privileges?');
                 }
             }
             if (!is_null($user_name)) {
                 if (!$this->setUser($user_name)) {
                     throw new RuntimeException('set user_name failed. are you sure you have the privileges?');
                 }
             }
             $children->run();
             exit;
             // redundant, added only for clarity
         } else {
             $children->setStarted(true);
             $this->children[] = $children;
             // Store the children's PID
             $children->setPid($pid);
             pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD));
         }
     }
 }
示例#3
0
 /**
  * Invoke filter
  * @param string $code
  * @param \WebLoader\Compiler $loader
  * @param string $file
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $loader, $file)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'less') {
         $code = Process::run("{$this->bin} -", $code, dirname($file), $this->env);
     }
     return $code;
 }
示例#4
0
 /**
  * Forks and run the process.
  *
  * @param Closure|string|array $callback A PHP callback to run whenever there is some
  *                                       output available on STDOUT or STDERR
  *
  * @return integer The exit status code
  */
 public function run($callback = null)
 {
     if (null === $this->commandline) {
         $this->commandline = $this->getPhpBinary();
     }
     parent::run($callback);
 }
示例#5
0
 /**
  * Tests Process::run
  */
 public function testRun()
 {
     $cmd = new Cmd('echo 1');
     $process = new Process();
     $process->addCommand($cmd);
     $res = $process->run();
     $this->assertEquals(0, $res->getCode(), 'echo should work everywhere');
 }
示例#6
0
 /**
  * Invoke filter
  *
  * @param string
  * @param \WebLoader\Compiler
  * @param string
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
         $cmd = $this->bin . ($this->compress ? ' -c' : '');
         $code = Process::run($cmd, $code);
     }
     return $code;
 }
示例#7
0
 /**
  * @param string
  * @param bool|NULL
  * @return string
  */
 public function compileCoffee($source, $bare = NULL)
 {
     if (is_null($bare)) {
         $bare = $this->bare;
     }
     $cmd = $this->bin . ' -p -s' . ($bare ? ' -b' : '');
     return Process::run($cmd, $source);
 }
示例#8
0
 /**
  * Copies the specified hook to your repos git hooks directory only if it
  * doesn't already exist!
  * @param  string $hook the hook to copy/symlink
  * @return void
  */
 public function copy($hook)
 {
     if (false === file_exists(self::GIT_HOOKS_PATH . $hook)) {
         // exec('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' ' . GIT_HOOKS_PATH . $hook);
         $copy = new Process('cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' .git/hooks/' . $hook);
         $copy->run();
     }
 }
示例#9
0
 protected function detectProcessorNumberByGrep()
 {
     if (Utils::findBin('grep') && file_exists('/proc/cpuinfo')) {
         $process = new Process('grep -c ^processor /proc/cpuinfo 2>/dev/null');
         $process->run();
         $this->processorNumber = intval($process->getOutput());
         return $this->processorNumber;
     }
     return;
 }
示例#10
0
 /**
  * Invoke filter
  *
  * @param  string $code
  * @param  \WebLoader\Compiler $compiler
  * @param  string $file
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $compiler, $file = NULL)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'ts') {
         $out = substr_replace($file, 'js', -2);
         $cmd = sprintf("%s %s --target ES5 --out %s", $this->bin, escapeshellarg($file), escapeshellarg($out));
         Process::run($cmd, NULL, NULL, $this->env);
         $code = file_get_contents($out);
     }
     return $code;
 }
示例#11
0
 public function run($callback = null)
 {
     if (null === $this->getCommandLine()) {
         if (false === ($php = $this->executableFinder->find())) {
             throw new \RuntimeException('Unable to find the PHP executable.');
         }
         $this->setCommandLine($php);
     }
     return parent::run($callback);
 }
示例#12
0
 /**
  * Invoke filter
  *
  * @param string
  * @param \WebLoader\Compiler
  * @param string
  * @return string
  */
 public function __invoke($code, \WebLoader\Compiler $loader, $file = NULL)
 {
     if (pathinfo($file, PATHINFO_EXTENSION) === 'styl') {
         $path = $cmd = $this->bin . ($this->compress ? ' -c' : '') . ($this->includeCss ? ' --include-css' : '') . ' -I ' . pathinfo($file, PATHINFO_DIRNAME);
         try {
             $code = Process::run($cmd, $code);
         } catch (\RuntimeException $e) {
             throw new \WebLoader\WebLoaderException('Stylus Filter Error', 0, $e);
         }
     }
     return $code;
 }
 /**
  * Execute la requete.
  */
 public function run()
 {
     // On envoie une deuxieme fois l'instance au gestionnaire d'erreurs
     // (1e fois = Webos->__construct())
     // Important pour ServerCallGroup !
     Error::setErrorsWebos($this);
     try {
         //On essaie d'executer l'action demandee
         $this->process->run();
     } catch (Exception $e) {
         //En cas d'erreur
         Error::catchException($e);
     }
     //On envoie la reponse HTTP
     $this->getHTTPResponse()->send();
 }
 public function fork(Process $children)
 {
     if ($this->allocateSHMPerChildren()) {
         $children->setSHMSegment(new \Zebra\Ipcs\SHMCache(\uniqid('process_manager;shm_per_children' . $children->getInternalId()), $this->allocateSHMPerChildren));
     }
     \pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD));
     $pid = \pcntl_fork();
     // Error
     if ($pid == -1) {
         throw new RuntimeException('pcntl_fork() returned -1, are you sure you are running the script from CLI?');
     } else {
         if (!$pid) {
             $children->run();
             exit;
             // redundant, added only for clarity
         } else {
             $children->setStarted(true);
             $this->children[] = $children;
             // Store the children's PID
             $children->setPid($pid);
             \pcntl_sigprocmask(SIG_UNBLOCK, array(SIGCHLD));
         }
     }
 }
 /**
  * Executes the given command via shell and returns the complete output as
  * a string
  *
  * @param string $command
  *
  * @return array(status, stdout, stderr)
  */
 protected function executeCommand($command)
 {
     if (class_exists('Symfony\\Component\\Process\\Process')) {
         $process = new \Symfony\Component\Process\Process($command, $this->env);
         if ($this->timeout !== false) {
             $process->setTimeout($this->timeout);
         }
     } else {
         $process = new Process($command, $this->env);
     }
     $process->run();
     return array($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
 }
示例#16
0
            break;
        case PROCESS_WARN_COLCOUNT:
            echo $warnPrefix . 'Line ' . $args[0] . " is invalid. Incorrect column count.\n";
            break;
        case PROCESS_WARN_EMPTYPATH:
            echo $warnPrefix . 'Line ' . $args[0] . " is invalid. The path must be at least one character long.\n";
            break;
        case PROCESS_WARN_WRITEFAIL:
            echo $warnPrefix . "Failed to write '" . $args[0] . (isset($args[1]) ? "' for '" . $args[1] : '') . "'.\n";
            break;
    }
}
$processor->setSizeGroups($sizeGroups);
$processor->setModifiedGroups($modifiedGroups);
$processor->setEventCallback('EventHandler');
$ret = $processor->run();
$processor->dumpProfiles();
if ($ret != PROCESS_OK && $processor->getVerboseLevel() > PROCESS_VERBOSE_QUIET) {
    $details = $processor->getFailDetails();
    switch ($ret) {
        case PROCESS_FAIL_OPEN_FILELIST:
            echo "FAIL: The <filelist> could not be opened.\n";
            break;
        case PROCESS_FAIL_INVALID_REPORTDIR:
            echo "FAIL: The <reportdir> already exists and is not a directory.\n";
            break;
        case PROCESS_FAIL_INVALID_HEADER:
            echo "FAIL: The header line in the <filelist> is invalid:\n" . $details['line'] . "\n";
            break;
        case PROCESS_FAIL_REPORTDIR_PARENT:
            echo "FAIL: The parent directory of <reportdir> does not exist.\n";
示例#17
0
 protected function install()
 {
     $install = new Process(sprintf('cd %s && php composer.phar install', $this->projectDir));
     $install->run();
     if ($install->isSuccessful()) {
         $output->writeln('<info>Packages succesfully installed</info>');
         return true;
     }
     $this->failingProcess = $install;
     return false;
 }
示例#18
0
 /**
  * Run
  */
 public function run()
 {
     $this->emit('run');
     $this->cluster->emit('run', $this);
     $this->child->run();
 }
示例#19
0
 public function isRunning()
 {
     if ($pid = $this->getPid()) {
         $process = new Process(sprintf('ps -p "%s"', $pid));
         $process->run();
         return $process->isSuccessful();
     }
     return false;
 }
示例#20
0
 function runProcess()
 {
     $process = new Process();
     $process->run();
 }
示例#21
0
 /**
  * Executes the given command via shell and returns the complete output as
  * a string
  *
  * @param  string $command
  *
  * @return array(status, stdout, stderr)
  */
 protected function executeCommand($command)
 {
     if (class_exists('Symfony\\Component\\Process\\Process')) {
         $process = new \Symfony\Component\Process\Process($command);
     } else {
         $process = new Process($command);
     }
     $process->run();
     return array($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
 }
 /**
  * Executes the given command via shell and returns the complete output as
  * a string
  *
  * @param string $command
  *
  * @return array(status, stdout, stderr)
  */
 protected function executeCommand($command)
 {
     $process = new Process($command, null, $this->env);
     if (false !== $this->timeout) {
         $process->setTimeout($this->timeout);
     }
     $process->run();
     return array($process->getExitCode(), $process->getOutput(), $process->getErrorOutput());
 }