appRoot = $appRoot; $this->translator = $translator; $output = new ConsoleOutput(); $input = new ArrayInput([]); $this->io = new DrupalStyle($input, $output); } /** * @param string $command * @param string $workingDirectory * * @throws ProcessFailedException * * @return Process */ public function exec($command, $workingDirectory=null) { if (!$workingDirectory || $workingDirectory==='') { $workingDirectory = $this->appRoot; } $this->io->newLine(); $this->io->comment( $this->translator->trans('commands.exec.messages.working-directory') .': ', false ); $this->io->writeln($workingDirectory); $this->io->comment( $this->translator->trans('commands.exec.messages.executing-command') .': ', false ); $this->io->writeln($command); $this->process = new Process($command); $this->process->setWorkingDirectory($workingDirectory); $this->process->enableOutput(); $this->process->setTimeout(null); $this->process->run( function ($type, $buffer) { $this->io->write($buffer); } ); if (!$this->process->isSuccessful()) { throw new ProcessFailedException($this->process); } return $this->process->isSuccessful(); } /** * @return string */ public function getOutput() { return $this->process->getOutput(); } }