diff --git a/src/Symfony/Component/Process/Pipes/UnixPipes.php b/src/Symfony/Component/Process/Pipes/UnixPipes.php index 73146356d4..2bf669733e 100644 --- a/src/Symfony/Component/Process/Pipes/UnixPipes.php +++ b/src/Symfony/Component/Process/Pipes/UnixPipes.php @@ -102,7 +102,7 @@ class UnixPipes extends AbstractPipes unset($r[0]); // let's have a look if something changed in streams - if ($r && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) { + if (($r || $w) && false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) { // if a system call has been interrupted, forget about it, let's try again // otherwise, an error occurred, let's reset pipes if (!$this->hasSystemCallBeenInterrupted()) { diff --git a/src/Symfony/Component/Process/Pipes/WindowsPipes.php b/src/Symfony/Component/Process/Pipes/WindowsPipes.php index bedac8feed..23e412ca3a 100644 --- a/src/Symfony/Component/Process/Pipes/WindowsPipes.php +++ b/src/Symfony/Component/Process/Pipes/WindowsPipes.php @@ -106,11 +106,15 @@ class WindowsPipes extends AbstractPipes public function readAndWrite($blocking, $close = false) { $this->unblock(); - $this->write(); + $w = $this->write(); + $read = $r = $e = array(); - $read = array(); - if ($this->fileHandles && $blocking) { - usleep(Process::TIMEOUT_PRECISION * 1E6); + if ($blocking) { + if ($w) { + @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); + } elseif ($this->fileHandles) { + usleep(Process::TIMEOUT_PRECISION * 1E6); + } } foreach ($this->fileHandles as $type => $fileHandle) { $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]); diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 32704df3f1..ebaa07ecd5 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -360,8 +360,7 @@ class Process do { $this->checkTimeout(); $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen(); - $close = '\\' !== DIRECTORY_SEPARATOR || !$running; - $this->readPipes(true, $close); + $this->readPipes($running, '\\' !== DIRECTORY_SEPARATOR || !$running); } while ($running); while ($this->isRunning()) { @@ -1295,14 +1294,15 @@ class Process } $this->processInformation = proc_get_status($this->process); + $running = $this->processInformation['running']; - $this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true); + $this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running); if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { $this->processInformation = $this->fallbackStatus + $this->processInformation; } - if (!$this->processInformation['running']) { + if (!$running) { $this->close(); } }