コード例 #1
0
 /**
  * Builds the full command to execute and stores it in $command.
  *
  * @return void
  * @uses   $command
  */
 protected function buildCommand()
 {
     if ($this->command === null && $this->commandline->getExecutable() === null) {
         throw new BuildException('ExecTask: Please provide "command" OR "executable"');
     } else {
         if ($this->command === null) {
             $this->realCommand = Commandline::toString($this->commandline->getCommandline(), $this->escape);
         } else {
             if ($this->commandline->getExecutable() === null) {
                 $this->realCommand = $this->command;
                 //we need to escape the command only if it's specified directly
                 // commandline takes care of "executable" already
                 if ($this->escape == true) {
                     $this->realCommand = escapeshellcmd($this->realCommand);
                 }
             } else {
                 throw new BuildException('ExecTask: Either use "command" OR "executable"');
             }
         }
     }
     if ($this->error !== null) {
         $this->realCommand .= ' 2> ' . escapeshellarg($this->error->getPath());
         $this->log("Writing error output to: " . $this->error->getPath(), $this->logLevel);
     }
     if ($this->output !== null) {
         $this->realCommand .= ' 1> ' . escapeshellarg($this->output->getPath());
         $this->log("Writing standard output to: " . $this->output->getPath(), $this->logLevel);
     } elseif ($this->spawn) {
         $this->realCommand .= ' 1>/dev/null';
         $this->log("Sending output to /dev/null", $this->logLevel);
     }
     // If neither output nor error are being written to file
     // then we'll redirect error to stdout so that we can dump
     // it to screen below.
     if ($this->output === null && $this->error === null && $this->passthru === false) {
         $this->realCommand .= ' 2>&1';
     }
     // we ignore the spawn boolean for windows
     if ($this->spawn) {
         $this->realCommand .= ' &';
     }
 }