This class represents a shell command.
Author: Michael Härtl (haertl.mike@gmail.com)
Example #1
0
File: Tor.php Project: yadakhov/tor
 /**
  * Execute tor command
  *
  * @param $command
  * @return Command|string
  */
 public function command($command)
 {
     if (!in_array($command, ['start', 'stop', 'restart', 'reload', 'force-reload', 'status'])) {
         throw new \InvalidArgumentException($command);
     }
     $command = 'sudo /etc/init.d/tor ' . $command;
     $command = new Command($command);
     $command->execute();
     return $command;
 }
Example #2
0
 public function up()
 {
     preg_match('/host=([^;]*)/', $this->db->dsn, $hostMatches);
     $hostName = $hostMatches[1];
     preg_match('/dbname=([^;]*)/', $this->db->dsn, $databaseMatches);
     $databaseName = $databaseMatches[1];
     preg_match('/port=([^;]*)/', $this->db->dsn, $portMatches);
     if (isset($portMatches[1])) {
         $port = $portMatches[1];
     } else {
         $port = "3306";
     }
     $command = new Command($this->mysqlExecutable);
     $command->addArg('-h', $hostName);
     $command->addArg('-P', $port);
     $command->addArg('-u', $this->db->username);
     $command->addArg('--password=', $this->db->password);
     $cmd = $command->getExecCommand() . " \"{$databaseName}\" < \"{$this->file}\"";
     #echo "    ".$cmd . "\n"; // TODO echo only with --verbose
     exec($cmd, $output, $return);
     if ($return !== 0) {
         //var_dump($output, $return);
         return false;
     } else {
         return true;
     }
 }
 /**
  * Displays application version from git describe and writes it to `version`
  */
 public function actionVersion($alias = '@app/version')
 {
     echo "Application Version\n";
     $cmd = new Command("git describe --dirty");
     if ($cmd->execute()) {
         echo $cmd->getOutput();
         file_put_contents(\Yii::getAlias($alias), $cmd->getOutput());
     } else {
         echo $cmd->getOutput();
         echo $cmd->getStdErr();
         echo $cmd->getError();
     }
     echo "\n";
 }
Example #4
0
 /**
  * @return string|bool the command to execute with optional Xfvb wrapper applied. Null if none set.
  */
 public function getExecCommand()
 {
     $command = parent::getExecCommand();
     if ($this->enableXvfb) {
         return $this->xvfbRunBinary . ' ' . $this->xvfbRunOptions . ' ' . $command;
     }
     return $command;
 }
 /**
  * Generate application and required vendor documentation
  */
 public function actionGenerateDocs()
 {
     if ($this->confirm('Regenerate documentation files into ./docs-html', true)) {
         // array with commands
         $commands[] = 'vendor/bin/apidoc guide --interactive=0 docs web/apidocs';
         $commands[] = 'vendor/bin/apidoc api --interactive=0 --exclude=runtime/,tests/,vendor/ . web/apidocs';
         $commands[] = 'vendor/bin/apidoc guide --interactive=0 docs web/apidocs';
         foreach ($commands as $command) {
             $cmd = new Command($command);
             if ($cmd->execute()) {
                 echo $cmd->getOutput();
             } else {
                 echo $cmd->getOutput();
                 echo $cmd->getStdErr();
                 echo $cmd->getError();
             }
         }
     }
 }
Example #6
0
 /**
  * @param $cmd
  *
  * @return mixed
  * @throws Exception
  */
 private function execute($cmd)
 {
     $command = new Command();
     $command->setCommand($cmd);
     if ($command->execute()) {
         return $command->getOutput();
     } else {
         throw new Exception($command->getError());
     }
 }
Example #7
0
 /**
  * @param string|null $filename the filename to add as 'output' option or null if none
  * @return bool whether the command was executed successfully
  */
 public function execute($filename = null)
 {
     $this->checkExecutionStatus();
     $this->processInputFiles();
     $this->processOperation();
     $this->processOptions($filename);
     return parent::execute();
 }
 /**
  * Execute docker-compose commande
  * @codeCoverageIgnore
  * @param Command $command The command to execute.
  */
 protected function execute($command)
 {
     if ($command->execute()) {
         $output = $command->getOutput();
     } else {
         $output = $command->getError();
     }
     return array('output' => $output, 'code' => $command->getExitCode());
 }
 public function testCanProvideProcDir()
 {
     $tmpDir = sys_get_temp_dir();
     $command = new Command('pwd');
     $command->procCwd = $tmpDir;
     $this->assertFalse($command->getExecuted());
     $this->assertTrue($command->execute());
     $this->assertTrue($command->getExecuted());
     $this->assertEquals($tmpDir, $command->getOutput());
 }