Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d54cd02

Browse filesBrowse files
[Process] Fix pipes cleaning on Windows
1 parent 0854c12 commit d54cd02
Copy full SHA for d54cd02

File tree

2 files changed

+26
-6
lines changed
Filter options

2 files changed

+26
-6
lines changed

‎src/Symfony/Component/Process/Pipes/WindowsPipes.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Pipes/WindowsPipes.php
+23-6Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,31 @@ public function __construct($disableOutput, $input)
4747
// Workaround for this problem is to use temporary files instead of pipes on Windows platform.
4848
//
4949
// @see https://bugs.php.net/bug.php?id=51800
50-
$this->files = array(
51-
Process::STDOUT => tempnam(sys_get_temp_dir(), 'out_sf_proc'),
52-
Process::STDERR => tempnam(sys_get_temp_dir(), 'err_sf_proc'),
50+
$pipes = array(
51+
Process::STDOUT => Process::OUT,
52+
Process::STDERR => Process::ERR,
5353
);
54-
foreach ($this->files as $offset => $file) {
55-
if (false === $file || false === $this->fileHandles[$offset] = @fopen($file, 'rb')) {
56-
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
54+
$tmpDir = sys_get_temp_dir();
55+
if (!@fopen($file = $tmpDir.'\\sf_proc_00.check', 'wb')) {
56+
throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
57+
}
58+
@unlink($file);
59+
for ($i = 0;; ++$i) {
60+
foreach ($pipes as $pipe => $name) {
61+
$file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
62+
if (file_exists($file) && !@unlink($file)) {
63+
continue 2;
64+
}
65+
$h = @fopen($file, 'xb');
66+
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
67+
continue 2;
68+
}
69+
if (isset($this->files[$pipe])) {
70+
@unlink($this->files[$pipe]);
71+
}
72+
$this->files[$pipe] = $file;
5773
}
74+
break;
5875
}
5976
}
6077

‎src/Symfony/Component/Process/Tests/ProcessTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ProcessTest.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ protected function tearDown()
5454

5555
public function testThatProcessDoesNotThrowWarningDuringRun()
5656
{
57+
if ('\\' === DIRECTORY_SEPARATOR) {
58+
$this->markTestSkipped('This test is transient on Windows');
59+
}
5760
@trigger_error('Test Error', E_USER_NOTICE);
5861
$process = $this->getProcess(self::$phpBin." -r 'sleep(3)'");
5962
$process->run();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.