Example #1
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');
 }
 /**
  * @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;
 }
 /**
  * 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;
 }
 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];
 }