start() public method

This method blocks until all STDIN data is sent to the process then it returns while the process runs in the background. The termination of the process can be awaited with wait(). The callback receives the type of output (out or err) and some bytes from the output in real-time while writing the standard input to the process. It allows to have feedback from the independent process during execution.
public start ( callable $callback = null )
$callback callable A PHP callback to run whenever there is some output available on STDOUT or STDERR
示例#1
1
 private static function setUpPhpServer()
 {
     self::$process = new Process('php -S [::1]:8999', __DIR__ . '/../../Resources/Scripts');
     self::$process->setTimeout(1);
     self::$process->start();
     usleep(100000);
 }
 /**
  * @When /^I run behat$/
  */
 public function iRunBehat()
 {
     $this->process->setWorkingDirectory($this->workingDir);
     $this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), strtr('--format-settings=\'{"timer": false}\'', array('\'' => '"', '"' => '\\"')), '--format=progress'));
     $this->process->start();
     $this->process->wait();
 }
示例#3
0
 public static function setUpBeforeClass()
 {
     $testDir = dirname(dirname(__DIR__));
     $cmd = "php -S 127.0.0.1:8000 -t {$testDir}/server/web {$testDir}/server/web/index.php";
     self::$serverProcess = new Process($cmd);
     self::$serverProcess->start();
 }
示例#4
0
 /**
  * Starts the internal PHP server using excerpts from my (awesome)
  * travel blog as the docroot.
  */
 public function startDemoServer()
 {
     $docRoot = realpath(__DIR__ . '/../../demo/mike-on-a-bike.com');
     $this->demoServerProcess = new Process('php -S ' . self::HOST . ' -t ' . $docRoot);
     $this->demoServerProcess->setTimeout(3600);
     $this->demoServerProcess->start();
 }
示例#5
0
 /**
  * @throws \RuntimeException if server could not be started within $this->timeout seconds
  */
 public function start()
 {
     if ($this->isRunning()) {
         return;
     }
     $processBuilder = new ProcessBuilder(['/usr/bin/php', '-S', "{$this->host}:{$this->port}", '-t', $this->webRoot]);
     $processBuilder->setTimeout(10);
     $this->serverProcess = $processBuilder->getProcess();
     $this->serverProcess->start();
     // server needs some time to boot up
     $serverIsBooting = true;
     $timeoutAt = time() + $this->timeout;
     while ($this->serverProcess->isRunning() && $serverIsBooting) {
         try {
             $socket = fsockopen($this->host, $this->port);
             if ($socket) {
                 $serverIsBooting = false;
             }
         } catch (\Exception $ex) {
             // server not ready
             if ($timeoutAt < time()) {
                 throw new \RuntimeException("Could not start Web Server [host = {$this->host}; port = {$this->port}; web root = {$this->webRoot}]");
             }
         }
         usleep(10);
     }
 }
示例#6
0
 /**
  * Runs behat command with provided parameters
  *
  * @When /^I run "behat(?: ((?:\"|[^"])*))?"$/
  *
  * @param string $argumentsString
  */
 public function iRunBehat($argumentsString = '')
 {
     $argumentsString = strtr($argumentsString, array('\'' => '"'));
     $this->process->setWorkingDirectory($this->workingDir);
     $this->process->setCommandLine(sprintf('%s %s %s %s', $this->phpBin, escapeshellarg(BEHAT_BIN_PATH), $argumentsString, strtr('--format-settings=\'{"timer": false}\' --no-colors', array('\'' => '"', '"' => '\\"'))));
     $this->process->start();
     $this->process->wait();
 }
示例#7
0
 /**
  * Private constructor for an local web server instance
  * @param $serverOptions
  * @param $workingDir
  */
 private function __construct($serverOptions, $workingDir)
 {
     echo "Creating local server with {$serverOptions} and working dir {$workingDir}\n";
     $this->waitForServerToStop();
     $this->process = new Process("php -S 127.0.0.1:6789 {$serverOptions}", $workingDir);
     $this->process->start();
     $this->waitForServerStart();
 }
 protected static function startServer()
 {
     if (!static::$enabled) {
         return;
     }
     self::$server = new Process(static::$command . ' &>/dev/null', __DIR__ . '/Fixtures');
     self::$server->start();
     static::pollWait();
 }
示例#9
0
 /**
  * Run the process.
  */
 public function run()
 {
     $this->process->start(function ($type, $buffer) {
         if (Process::ERR === $type) {
             $this->pipe->error($buffer);
         } else {
             $this->pipe->output($buffer);
         }
     });
     $this->waitStrategy->wait($this->process);
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function start()
 {
     if (isset($this->deferred)) {
         throw new \RuntimeException('Tasks is already started');
     }
     $this->deferred = new Deferred();
     $this->process->start(function () {
         $this->outputBuffer->enqueue(func_get_args());
     });
     return $this->deferred->promise();
 }
 public function startServer()
 {
     $finder = new PhpExecutableFinder();
     if (false === ($binary = $finder->find())) {
         throw new \RuntimeException('Unable to find PHP binary to run server.');
     }
     $builder = new ProcessBuilder(['exec', $binary, '-S', $this->address, realpath(__DIR__ . '/../Resource/server.php')]);
     $builder->setWorkingDirectory(realpath(__DIR__ . '/../Resource'));
     $builder->setTimeout(null);
     $this->process = $builder->getProcess();
     $this->process->start();
     $this->waitServer();
 }
 public function beforeSuite()
 {
     $router = '' != $this->router ? escapeshellarg($this->router) : '';
     // See https://github.com/symfony/symfony/issues/5030 for why exec
     // is used here
     $this->process = new Process(sprintf('exec php -S %s -t %s %s', escapeshellarg($this->host), escapeshellarg($this->docroot), $router));
     $this->process->start();
     sleep(1);
     if (!$this->process->isRunning()) {
         throw new \RuntimeException('PHP built-in server process terminated immediately');
     }
     // Also trap fatal errors to make sure running processes are terminated
     register_shutdown_function([$this, 'afterSuite']);
 }
 /**
  * {@inheritDoc}
  *
  * Starts the connection
  */
 public function _reconfigure($config = array())
 {
     parent::_reconfigure($config);
     if (!isset($this->config['username'])) {
         throw new \Exception("Sauce Connect Extension requires a username.");
     }
     if (!isset($this->config['accesskey'])) {
         throw new \Exception("Sauce Connect Extension requires a accesskey.");
     }
     $connect = __DIR__ . '/../../../bin/sauce_connect';
     if (!file_exists($connect)) {
         $connect = __DIR__ . '/../../../../bin/sauce_connect';
     }
     if (!file_exists($connect)) {
         throw new \Exception("Couldnt find the bin directory... Make sure its in ./bin or ./vendor/bin/");
     }
     $processBuilder = new ProcessBuilder([$connect]);
     $processBuilder->addEnvironmentVariables(['SAUCE_USERNAME' => $this->config['username'], 'SAUCE_ACCESS_KEY' => $this->config['accesskey']]);
     $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 60;
     $this->process = $processBuilder->getProcess();
     $this->process->setTimeout(0);
     $this->process->start(function ($type, $buffer) {
         $buffer = explode("\n", $buffer);
         foreach ($buffer as $line) {
             if (strpos($line, 'Press any key to see more output') === false) {
                 file_put_contents(codecept_output_dir() . 'sauce_connect.log', $line . "\n", FILE_APPEND);
             }
         }
     });
     $timer = 0;
     $connected = false;
     $this->writeln(["", "----------------------------------------------------------------------------", "Attempting to connect to SauceLabs. Waiting {$timeout} seconds."]);
     while ($this->process->isRunning() && $timer < $timeout) {
         $output = $this->process->getOutput();
         if (strpos($output, 'Connected! You may start your tests.') !== false) {
             $connected = true;
             break;
         }
         sleep(1);
         $timer++;
         if ($timer % 5 === 0) {
             $this->write('.');
         }
     }
     if (false === $connected) {
         $this->process->stop();
         throw new \Exception(sprintf("Could not start tunnel. Check %ssauce_connect.log for more information.", codecept_output_dir()));
     }
     $this->writeln(["", "Connected to SauceLabs", "----------------------------------------------------------------------------", ""]);
 }
示例#14
0
 /**
  * @BeforeScenario
  * @param ScenarioEvent $event
  */
 public function startCapture(ScenarioEvent $event)
 {
     if ($this->tagFilter !== NULL && !in_array($this->tagFilter, $event->getScenario()->getTags(), TRUE)) {
         return;
     }
     if ((string) $this->display === '') {
         throw new Exception('No display parameter given and no DISPLAY environment variable set.');
     }
     // TODO Check for existence of ffmpeg
     // We need to add "exec" before the actual command to allow the correct termination of a subprocess
     $ffmpeg = new ProcessBuilder(array('exec', $this->pathToFfmpeg, '-y', '-r', $this->frameRate, '-f', 'x11grab', '-s', $this->size, '-i', $this->display, '-vc', 'x264', '-pix_fmt', 'yuv420p', $this->getTmpFilename()));
     $this->captureProcess = $ffmpeg->getProcess();
     $this->captureProcess->start();
     // TODO Check for errors
 }
示例#15
0
文件: Server.php 项目: tillk/vufind
 /**
  * Starts the server process
  *
  * @param Process $process A process object
  *
  * @throws \RuntimeException
  */
 public function start(Process $process = null)
 {
     // Check if the server script exists at given path
     if (false === $this->serverPath || false === is_file($this->serverPath)) {
         throw new \RuntimeException(sprintf("Could not find server script at path '%s'", $this->serverPath));
     }
     // Create process object if neccessary
     if (null === $process) {
         $processBuilder = new ProcessBuilder(array($this->nodeBin, $this->serverPath));
         $process = $processBuilder->getProcess();
     }
     $this->process = $process;
     // Start server process
     $this->process->start();
     $this->connection = null;
     // Wait for the server to start up
     $time = 0;
     $successString = sprintf("server started on %s:%s", $this->host, $this->port);
     while ($this->process->isRunning() && $time < $this->threshold) {
         if ($successString == trim($this->process->getOutput())) {
             $this->connection = new Connection($this->host, $this->port);
             break;
         }
         usleep(1000);
         $time += 1000;
     }
     // Make sure the server is ready or throw an exception otherwise
     $this->checkAvailability();
 }
示例#16
0
 /**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output, $retried = false)
 {
     if ($this->getContainer()->get('foreman.accessor')->ping()) {
         $output->writeln('<error>The Foreman Processor server is already running.');
         return;
     }
     if ($input->getOption('daemon')) {
         $phpPath = (new PhpExecutableFinder())->find();
         $process = new Process($phpPath . ' app/console foreman:processor:start' . ($input->getOption('verbose') ? ' -v' : ''));
         $process->setTimeout(0);
         $output->writeln('<info>Starting daemon server...');
         $process->start();
         $accessor = $this->getContainer()->get('foreman.accessor');
         $start = time();
         $interval = $this->getContainer()->getParameter('foreman.processor')['interval'];
         //When we try to ping the server the first time, it almost always fails.
         //The server isn't started yet by the time we get here, so we wait.
         //Timeout = 3 seconds. Should be enough for all servers.
         while (!$accessor->ping() && time() - $start < 3) {
             sleep($interval);
         }
         if ($accessor->ping()) {
             $status = $accessor->status();
             $output->writeln('<info>The server was started successfully with PID ' . $status['pid'] . '</info>');
         } else {
             $output->writeln('<error>The server could not be started at this moment.</error>');
             $output->writeln('Please check if the server port (' . $this->getContainer()->getParameter('foreman.processor.port') . ') is available.');
             $output->writeln('If you have closed the server recently, the connection may not have released. Try again ' . 'in a few seconds.');
         }
     } else {
         $output->writeln('<info>Starting the Foreman Processor...</info>');
         $this->getContainer()->get('foreman.processor')->start($output, $input->getOption('verbose'));
     }
 }
示例#17
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $distribution = $input->getArgument('distribution');
     $version = $input->getArgument('version');
     $download = $this->downloadProject($distribution, $version);
     $process = new Process("tar -xzf {$download['location']} -C /tmp/");
     $process->start();
     if (substr($version, 0, 3) == '7.x') {
         $finder = new Finder();
         $process->wait();
         // Find all modules dropped in to the distribution.
         $finder->files()->name("*.info");
         $filename = array();
         foreach ($finder->in($download['locationUncompressed']) as $file) {
             $filename[] = array('path' => $file->getRealPath(), 'filename' => $file->getFileName());
         }
         // Create the array for the containing modules.
         $return = array();
         foreach ($filename as $file) {
             $contents = $this->parse_info_file(file_get_contents($file['path']));
             $machine_name = substr($file['filename'], 0, strpos($file['filename'], '.'));
             $return[$machine_name] = array('name' => $contents['name'], 'machine_name' => substr($file['filename'], 0, strpos($file['filename'], '.')), 'core' => $contents['core'], 'version' => $contents['version'], 'status' => 'Enabled', 'package' => isset($contents['package']) ? $contents['package'] : null);
         }
         $output->write(json_encode($return));
     }
 }
示例#18
0
 public function testControlledExit()
 {
     if (!extension_loaded('pcntl')) {
         $this->markTestSkipped('PCNTL extension is not loaded.');
     }
     $proc = new Process('exec ' . PHP_BINARY . ' ' . escapeshellarg(__DIR__ . '/console') . ' jms-job-queue:run --worker-name=test --verbose --max-runtime=999999');
     $proc->start();
     usleep(500000.0);
     $this->assertTrue($proc->isRunning(), 'Process exited prematurely: ' . $proc->getOutput() . $proc->getErrorOutput());
     $this->assertTrueWithin(3, function () use($proc) {
         return false !== strpos($proc->getOutput(), 'Signal Handlers have been installed');
     }, function () use($proc) {
         $this->fail('Signal handlers were not installed: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $proc->signal(SIGTERM);
     $this->assertTrueWithin(3, function () use($proc) {
         return false !== strpos($proc->getOutput(), 'Received SIGTERM');
     }, function () use($proc) {
         $this->fail('Signal was not received by process within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $this->assertTrueWithin(3, function () use($proc) {
         return !$proc->isRunning();
     }, function () use($proc) {
         $this->fail('Process did not terminate within 3 seconds: ' . $proc->getOutput() . $proc->getErrorOutput());
     });
     $this->assertContains('All jobs finished, exiting.', $proc->getOutput());
 }
示例#19
0
 /**
  * {@inheritdoc}
  */
 public function start($callback = null)
 {
     if (null === $this->getCommandLine()) {
         throw new RuntimeException('Unable to find the PHP executable.');
     }
     parent::start($callback);
 }
 /**
  * @Route("/", name="write_register", options={"expose"=true})
  * @param Request $request
  * @return JsonResponse
  */
 public function writeAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $value = $request->get("value");
         $register_id = $request->get("register_id");
         $registerRepo = $this->getDoctrine()->getRepository('BmsConfigurationBundle:Register');
         $register = $registerRepo->find($register_id);
         $em = $this->getDoctrine()->getManager();
         $write = new RegisterWriteData();
         $write->setRegister($register)->setGetToProcess(0)->setValue($value)->setSuccessWrite(0)->setTimeOfUpdate(new \DateTime())->setUsername($this->getUser());
         $em->persist($write);
         $em->flush();
         $vpn = $this->getParameter('vpn');
         $exe = "ssh pi@" . $vpn . " ./bin/addToWrite.sh " . $register_id . " " . $value . " " . $this->getUser();
         $process = new Process($exe);
         $process->start();
         while ($process->isRunning()) {
             // waiting for process to finish
         }
         $ret['output'] = $process->getOutput();
         return new JsonResponse($ret);
     } else {
         throw new AccessDeniedHttpException();
     }
 }
示例#21
0
 /**
  * @dataProvider cbProvider
  */
 public function testResponse($expectedStatusCode, $expectedResponseContent, $request, $testCase, $testHeaders)
 {
     $process = new Process('php -S [::1]:8999', __DIR__ . '/../../resources');
     $process->start();
     sleep(1);
     $signature = sha1($request . ServerMock::PROJECT_SECRET_KEY);
     $headers = null;
     if ($testHeaders) {
         $headers = $testHeaders;
     } else {
         $headers = array('Authorization' => 'Signature ' . $signature);
     }
     $request = $this->guzzleClient->post('/webhook_server.php?test_case=' . $testCase, $headers, $request);
     try {
         $response = $request->send();
     } catch (BadResponseException $e) {
         $process->stop();
         $response = $e->getResponse();
     }
     static::assertSame($expectedResponseContent, $response->getBody(true));
     static::assertSame($expectedStatusCode, $response->getStatusCode());
     static::assertArrayHasKey('x-xsolla-sdk', $response->getHeaders());
     static::assertSame(Version::getVersion(), (string) $response->getHeader('x-xsolla-sdk'));
     static::assertArrayHasKey('content-type', $response->getHeaders());
     if (204 === $response->getStatusCode()) {
         static::assertStringStartsWith('text/plain', (string) $response->getHeader('content-type'));
     } else {
         static::assertStringStartsWith('application/json', (string) $response->getHeader('content-type'));
     }
 }
 /**
  * Starts a wiremock process.
  *
  * @param string $jarPath
  * @param string $logsPath
  * @param string $arguments
  *
  * @throws \Exception
  */
 public function start($ip, $port, $path, $logsPath, $debug)
 {
     $phiremockPath = is_file($path) ? $path : "{$path}/phiremock";
     $this->process = new Process($this->getCommandPrefix() . "{$phiremockPath} -i {$ip} -p {$port}" . ($debug ? ' -d' : ''));
     if ($debug) {
         echo 'Executing: ' . $this->process->getCommandLine() . PHP_EOL;
     }
     $logFile = $logsPath . DIRECTORY_SEPARATOR . self::LOG_FILE_NAME;
     $this->process->start(function ($type, $buffer) use($logFile) {
         file_put_contents($logFile, $buffer, FILE_APPEND);
     });
     $this->process->setEnhanceSigchildCompatibility(true);
     if ($this->isWindows()) {
         $this->process->setEnhanceWindowsCompatibility(true);
     }
 }
 public function testHttpDataDownloadUsingManyWorkers()
 {
     $filesystem = new Filesystem();
     $targetDirPath = TEMP_DIR . '/' . uniqid('test_http_download');
     $filesystem->mkdir($targetDirPath);
     $workersManager = new Process('php ' . BIN_DIR . '/spider.php worker:start-many -c 3');
     $workersManager->start();
     $this->assertTrue($workersManager->isRunning(), 'Workers Manager should be working');
     $collector = new Process('php ' . BIN_DIR . '/spider.php collector:start --target-folder=' . $targetDirPath);
     $collector->setIdleTimeout(10);
     // there should be an output/result at least once every 10 seconds
     $collector->start();
     $this->assertTrue($collector->isRunning(), 'Task Results Collector should be working');
     $taskLoader = new Process('php ' . BIN_DIR . '/spider.php tasks:load < ' . FIXTURES_DIR . '/uris.txt');
     $taskLoader->setTimeout(120);
     // 120 seconds is enough to complete the task
     $taskLoader->start();
     $this->assertTrue($taskLoader->isRunning(), 'Task Loader should be working');
     while ($taskLoader->isRunning()) {
         sleep(1);
         // waiting for process to complete
     }
     $taskLoaderOutput = $taskLoader->getOutput() . $taskLoader->getErrorOutput();
     $this->assertContains('Total count of Tasks put in the Queue: 10', $taskLoaderOutput, 'Task Loader should have loaded 10 Tasks');
     $this->assertContains('Waiting for acknowledgement from Task Result Collector', $taskLoaderOutput, 'Task Loader should have been waiting for Task Result Collector acknowledgement');
     $this->assertContains('Informing all workers to stop', $taskLoaderOutput, 'Task Loader should have inform Workers to stop');
     $fi = new \FilesystemIterator($targetDirPath, \FilesystemIterator::SKIP_DOTS);
     $this->assertEquals(10, iterator_count($fi), '10 Task Result Files expected');
 }
示例#24
0
 /**
  * Starts the server
  *
  * @param array $options
  * @return void
  */
 public function start(array $options)
 {
     $verbose = isset($options['verbose']) && $options['verbose'];
     if ($this->checkServer()) {
         $this->output->writeln("<error>Queue Manager is already running.</error>");
         return;
     }
     if ($verbose) {
         $this->output->writeln("<info>Queue Manager is starting.</info>");
     }
     $phpFinder = new PhpExecutableFinder();
     $phpPath = $phpFinder->find();
     if ($options['daemon']) {
         $command = $phpPath . ' app/console naroga:queue:start ' . ($verbose ? '-v' : '') . ' &';
         $app = new Process($command);
         $app->setTimeout(0);
         $app->start();
         $pid = $app->getPid();
         $this->memcache->replace('queue.lock', $pid);
         if ($verbose) {
             $this->output->writeln('<info>Queue Manager started with PID = ' . ($pid + 1) . '.</info>');
         }
         return;
     }
     $this->registerListeners($verbose);
     if ($verbose) {
         $pid = $this->memcache->get('queue.lock');
         $this->output->writeln('<info>Queue Manager started with PID = ' . $pid . '.</info>');
     }
     $this->resetServerConfig($options);
     $this->processQueue($options);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $commandLine = 'sudo php ' . $this->getContainer()->get('kernel')->getRootDir() . '/console websocket:server:start ' . $input->getArgument('host');
     $output->writeln($commandLine);
     $process = new Process($commandLine);
     $process->start();
 }
 /**
  * Run a terminal command
  * @param  [array]         $command  [description]
  * @param  [path]          $directory [description]
  * @param  OutputInterface $output    [description]
  * @return [void]                     [description]
  */
 private function runProcess($command, $directory, $output, $alias)
 {
     $output->writeln('');
     if (is_array($command['line'])) {
         $commandLine = implode(' && ', $command['line']);
     } else {
         $commandLine = $command['line'];
     }
     $process = new Process($commandLine, $directory);
     $process->setTimeout(7600);
     $process->start();
     if ($output->isVerbose()) {
         $process->wait(function ($type, $buffer) {
             echo $buffer;
         });
     } else {
         $progress = new ProgressBar($output);
         $progress->setFormat("<comment>%message%</comment> [%bar%]");
         $progress->setMessage($command['title']);
         $progress->start();
         $progress->setRedrawFrequency(10000);
         while ($process->isRunning()) {
             $progress->advance();
         }
         $progress->finish();
         $progress->clear();
     }
     $output->writeln('');
     $output->write('<comment>' . $command['title'] . ' </comment><info>√ done</info>');
 }
示例#27
0
文件: Exec.php 项目: sliver/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (!$this->background and !$this->isPrinted) {
         $this->process->run();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     if (!$this->background and $this->isPrinted) {
         $this->process->run(function ($type, $buffer) {
             Process::ERR === $type ? print 'ER» ' . $buffer : (print '» ' . $buffer);
         });
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput());
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $server = new Process('php -S 127.0.0.1:4295', __DIR__ . '/../html');
     $server->start();
     self::setServer($server);
 }
示例#29
0
文件: Exec.php 项目: stefanhuber/Robo
 public function run()
 {
     $command = $this->getCommand();
     $dir = $this->workingDirectory ? " in " . $this->workingDirectory : "";
     $this->printTaskInfo("Running <info>{$command}</info>{$dir}");
     $this->process = new Process($command);
     $this->process->setTimeout($this->timeout);
     $this->process->setIdleTimeout($this->idleTimeout);
     $this->process->setWorkingDirectory($this->workingDirectory);
     if (isset($this->env)) {
         $this->process->setEnv($this->env);
     }
     if (!$this->background and !$this->isPrinted) {
         $this->startTimer();
         $this->process->run();
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     if (!$this->background and $this->isPrinted) {
         $this->startTimer();
         $this->process->run(function ($type, $buffer) {
             print $buffer;
         });
         $this->stopTimer();
         return new Result($this, $this->process->getExitCode(), $this->process->getOutput(), ['time' => $this->getExecutionTime()]);
     }
     try {
         $this->process->start();
     } catch (\Exception $e) {
         return Result::error($this, $e->getMessage());
     }
     return Result::success($this);
 }
 public function runCrons()
 {
     $entityManager = $this->managerRegistry->getManagerForClass('DspSoftsCronManagerBundle:CronTask');
     $cronTaskRepo = $entityManager->getRepository('DspSoftsCronManagerBundle:CronTask');
     $cronTasks = $cronTaskRepo->findCronsToLaunch();
     foreach ($cronTasks as $cronTask) {
         $run = true;
         if (!$cronTask->getRelaunch()) {
             $run = $this->planificationChecker->isExecutionDue($cronTask->getPlanification());
         }
         if ($run) {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Running Cron Task <info>%s</info>', $cronTask->getName()));
             }
             $cli = 'exec ' . $this->kernelRootDir . DIRECTORY_SEPARATOR . 'console dsp:cron:runjob -c ' . $cronTask->getId() . ' &';
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Command line : <info>%s</info>', $cli));
             }
             $process = new Process($cli);
             $process->setTimeout(0);
             $process->start();
         } else {
             if ($this->logger !== null) {
                 $this->logger->info(sprintf('Skipping Cron Task <info>%s</info>', $cronTask->getName()));
             }
         }
     }
 }