diff --git a/src/Symfony/Component/Process/Pipes/WindowsPipes.php b/src/Symfony/Component/Process/Pipes/WindowsPipes.php index 23e412ca3a..071dd0334a 100644 --- a/src/Symfony/Component/Process/Pipes/WindowsPipes.php +++ b/src/Symfony/Component/Process/Pipes/WindowsPipes.php @@ -47,14 +47,31 @@ class WindowsPipes extends AbstractPipes // Workaround for this problem is to use temporary files instead of pipes on Windows platform. // // @see https://bugs.php.net/bug.php?id=51800 - $this->files = array( - Process::STDOUT => tempnam(sys_get_temp_dir(), 'out_sf_proc'), - Process::STDERR => tempnam(sys_get_temp_dir(), 'err_sf_proc'), + $pipes = array( + Process::STDOUT => Process::OUT, + Process::STDERR => Process::ERR, ); - foreach ($this->files as $offset => $file) { - if (false === $file || false === $this->fileHandles[$offset] = @fopen($file, 'rb')) { - throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable'); + $tmpDir = sys_get_temp_dir(); + if (!@fopen($file = $tmpDir.'\\sf_proc_00.check', 'wb')) { + throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable'); + } + @unlink($file); + for ($i = 0;; ++$i) { + foreach ($pipes as $pipe => $name) { + $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); + if (file_exists($file) && !@unlink($file)) { + continue 2; + } + $h = @fopen($file, 'xb'); + if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) { + continue 2; + } + if (isset($this->files[$pipe])) { + @unlink($this->files[$pipe]); + } + $this->files[$pipe] = $file; } + break; } } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index ce06f1c338..f06b135e26 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -54,6 +54,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase public function testThatProcessDoesNotThrowWarningDuringRun() { + if ('\\' === DIRECTORY_SEPARATOR) { + $this->markTestSkipped('This test is transient on Windows'); + } @trigger_error('Test Error', E_USER_NOTICE); $process = $this->getProcess(self::$phpBin." -r 'sleep(3)'"); $process->run();