2

如何在后台运行 Symfony2 进程?

我的代码:

class Start extends Symfony\Component\Console\Command\Command {

  protected function configure() {
    $this->setName('start');
  }

  protected function execute(InputInterface $input, OutputInterface $output) {
    $process = new Process('java -jar ./selenium-server-standalone-2.42.2.jar');
    $process->setTimeout(null);
    $process->start();
    $pid = $process->getPid();
    $output->writeLn(sprintf('Started selenium with PID %d', $pid));
    $process->wait();
  }

}

如何在后台运行此过程?我想我应该将新进程的 STDOUT 重定向到 /dev/null 但我该怎么做呢?

4

1 回答 1

0

Oh, I found it is possible in Symfony 2.5+, so I just updated it and added

$process->disableOutput(); 

before $process->start() and it works fine.

UPD.

Unfortunately, it does not work on Windows. I also tried to run 'START /B command' and

'CALL command > nul 2>&1' 

but both of these failed: process was running but console was still blocked.

于 2014-09-09T17:29:06.073 回答