예제 #1
0
 public function testExecRunsCommandBuilder()
 {
     $shell = new Exec();
     $command = new CommandBuilder('touch');
     $command->addParam($this->testFile);
     $shell->run($command);
     $this->assertTrue(file_exists($this->testFile), sprintf('%s should have been created', $this->testFile));
 }
 /**
  * @return bool
  */
 public function checkLibaryIsInstalled()
 {
     $shell = new Exec();
     $command = new Command($this->binaryPath);
     $command->addArgument(new Command\Argument('version'));
     $shell->run($command);
     if ($shell->getReturnValue() === 0) {
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * Get the output of the body.
  *
  * @access public
  * @param string $type - Either Command::HTML or Command::TEXT
  * @param mixed $body
  * @return string
  */
 public function getOutput($type, $body)
 {
     $command = new CommandBuilder($this->command);
     $tempFileName = $this->getTmpFile($body);
     //Set output type to $type
     $command->addArgument('mode', $type);
     //Add temporary file as parameter
     $command->addParam($tempFileName);
     $shell = new Exec();
     $shell->run($command);
     unlink($tempFileName);
     return implode("\n", $shell->getOutput());
 }
 /**
  * Runs a shell command, logs, and handles the result.
  *
  * @param AdamBrett\ShellWrapper\CommandInterface $cmd The text of the command to be run
  *
  * @return bool True if the command was successful, false on error
  */
 private function ex(CommandInterface $cmd)
 {
     // try to run the command
     $this->shell->run($cmd);
     $output = $this->shell->getOutput();
     $returnValue = $this->shell->getReturnValue();
     // record the result
     $output = count($output) ? implode("\n", $output) . "\n" : '';
     $this->result['output'] .= "{$cmd}\n{$output}";
     // return a boolean
     return 0 === $returnValue;
 }
예제 #5
0
 public function generateTestAndKey()
 {
     //        if($missing = $this->getMissingParams(['title', 'copyright'])) {
     //            return response()->json(['error' => 'Missing params', 'missing' => $missing], 422);
     //        }
     $uniqId = uniqid();
     //        putenv("LANG='en_US.UTF-8'");
     //        putenv("LC_ALL='en_US.UTF-8'");
     $shell = new Exec();
     $cmd = new CommandBuilder(env('RUDI_PATH', './rudi/rudi'));
     $cmd->addArgument('output', './' . $uniqId);
     if (Input::has('title')) {
         $cmd->addArgument('title', Input::get('title'));
     }
     if (Input::has('copyright')) {
         $cmd->addArgument('copyright', Input::get('copyright'));
     }
     foreach ($this->nameToArgument as $name => $arg) {
         if (Input::has($name)) {
             if (Input::has($name . "-count")) {
                 $cmd->addArgument($arg, Input::get($name . "-count"));
             } else {
                 $cmd->addArgument($arg);
             }
         }
     }
     \Log::info($cmd);
     $shell->run($cmd);
     if ($shell->getReturnValue() !== 0) {
         return response()->json($shell->getOutput(), 500);
     }
     $output = '';
     $testString = 'lilypond ' . $uniqId . '.ly ' . $uniqId . '.pdf';
     $keyString = 'lilypond ' . $uniqId . '-key.ly ' . $uniqId . '-key.pdf';
     exec($testString, $output);
     exec($keyString, $output);
     unlink($uniqId . '.ly');
     unlink($uniqId . '-key.ly');
     return ['id' => $uniqId];
 }
예제 #6
0
 public function testCanGetReturnValue()
 {
     $shell = new Exec();
     $shell->run(new Command('ls'));
     $this->assertEquals(ExitCodes::SUCCESS, $shell->getReturnValue(), 'The return should be a success');
     $this->assertInternalType('integer', $shell->getReturnValue(), 'The should be a return value');
     $shell->run(new Command('/dev/null 2>/dev/null'));
     $this->assertEquals(ExitCodes::PERMISSION_ERROR, $shell->getReturnValue(), 'The return should be an error');
 }
예제 #7
0
<?php

require 'vendor/autoload.php';
use AdamBrett\ShellWrapper\Command;
use AdamBrett\ShellWrapper\Command\Param;
use AdamBrett\ShellWrapper\Runners\Exec;
$shell = new Exec();
$command = new Command('echo');
$command->addParam(new Param('Bonjour'));
$shell->run($command);
$shell2 = new Exec();
$command2 = new Command('echo');
$command2->addParam(new Param('Saviez-vous que les fourmis sont parfois paresseuses ?'));
$shell2->run($command2);
/*
$command3 = new Command('ls');
$shell->run($command3);
print_r($shell->getOutput()); 
*/