Skip to content
Advertisement

Symfony process executes command but returns failed status

By doing

public function spawn_queue_process(){
   $command = 'echo hi > find_me.txt';

      $process = new Process($command);
      $process->setWorkingDirectory(base_path());
      $process->start();

      //Just in case :-)
      Log::error($process->getOutput());

      if(!$process->isSuccessful()){
         $exception = new ProcessFailedException($process);
         Log::error('Error on queue call');
         Log::error($exception->getTraceAsString());
      }
   }

Even though the file is created, Symfony will throw an exception everytime, rendering useless everything inside $process output and making my program freak out about it.

Any ideas?

EDIT: Just for clarification, I got a way more complex command than this running on Linux with no problem, Windows Server however will fail on every single instance of process code.

Advertisement

Answer

Solved.

Make sure you make a (rather weird) work around when executing this type of commands. Wether you expect the command to be sync or async executed, you gotta wait for the command to be procesed by the server. You can do this by using:

$process = new Process($command);
$process->start();

//Block before command is finished sending (still async)
while($process->isRunning()){}

if(!$process->isSuccessful()){
   $exception = new ProcessFailedException($process);
   Log::error($exception->getTraceAsString());
}

Otherwise the command will evaluate as still running(when actually its just being sent) and mark it as non completed.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement