Platformsh\Cli\Helper\ShellHelper::execute PHP Method

execute() public method

public execute ( array $args, $dir = null, $mustRun = false, $quiet = true )
$args array
    public function execute(array $args, $dir = null, $mustRun = false, $quiet = true)
    {
        $builder = new ProcessBuilder($args);
        $process = $builder->getProcess();
        $process->setTimeout($this->defaultTimeout);
        if ($dir) {
            $process->setWorkingDirectory($dir);
        }
        $result = $this->runProcess($process, $mustRun, $quiet);
        return is_int($result) ? $result === 0 : $result;
    }

Usage Example

 /**
  * Test ShellHelper::execute().
  */
 public function testExecute()
 {
     $shellHelper = new ShellHelper();
     // Find a command that will work on all platforms.
     $workingCommand = strpos(PHP_OS, 'WIN') !== false ? 'help' : 'pwd';
     // With $mustRun disabled.
     $this->assertNotEmpty($shellHelper->execute(array($workingCommand)));
     $this->assertFalse($shellHelper->execute(array('which', 'nonexistent')));
     // With $mustRun enabled.
     $this->assertNotEmpty($shellHelper->execute(array($workingCommand), null, true));
     $this->setExpectedException('Exception');
     $shellHelper->execute(array('which', 'nonexistent'), null, true);
 }