2

How can I run a Symfony2 process in background?

My code:

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();
  }

}

How can I run this process in background? I guess I should redirect STDOUT of the new process to /dev/null but how can I do that?

luchaninov
  • 6,792
  • 6
  • 60
  • 75
NikitaObukhov
  • 193
  • 1
  • 2
  • 10

1 Answers1

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.

NikitaObukhov
  • 193
  • 1
  • 2
  • 10