Skip to content

Commit

Permalink
Merge pull request #153 from phaseinducer/patch-1
Browse files Browse the repository at this point in the history
Add an exception in case of �proc_open() failure
  • Loading branch information
docteurklein committed Apr 16, 2015
2 parents eda1b39 + fa7467c commit 904df09
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Knp/Snappy/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ public function run()

$process = proc_open($this->command, $descriptorspec, $pipes, null, $this->env);

if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// 2 => readable handle connected to child stderr
if (!is_resource($process)) {
throw new \RuntimeException('Unable to launch a new process.');
}

$this->output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// 2 => readable handle connected to child stderr

$this->errorOutput = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$this->output = stream_get_contents($pipes[1]);
fclose($pipes[1]);

// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$this->exitCode = proc_close($process);
}
$this->errorOutput = stream_get_contents($pipes[2]);
fclose($pipes[2]);

// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$this->exitCode = proc_close($process);
}

/**
Expand Down

0 comments on commit 904df09

Please sign in to comment.