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 aee7694

Browse filesBrowse files
[Process] Fix pipes cleaning on Windows
1 parent a0cdcb0 commit aee7694
Copy full SHA for aee7694

File tree

1 file changed

+16
-20
lines changed
Filter options

1 file changed

+16
-20
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Pipes/WindowsPipes.php
+16-20Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ 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 (false === @fopen($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+
for ($i = 0;; ++$i) {
59+
foreach ($pipes as $pipe => $name) {
60+
@unlink($file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name));
61+
$h = @fopen($file, 'xb');
62+
if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
63+
continue 2;
64+
}
65+
$this->files[$pipe] = $file;
5766
}
67+
break;
5868
}
5969
}
6070

@@ -64,7 +74,6 @@ public function __construct($disableOutput, $input)
6474
public function __destruct()
6575
{
6676
$this->close();
67-
$this->removeFiles();
6877
}
6978

7079
/**
@@ -164,17 +173,4 @@ public static function create(Process $process, $input)
164173
{
165174
return new static($process->isOutputDisabled(), $input);
166175
}
167-
168-
/**
169-
* Removes temporary files.
170-
*/
171-
private function removeFiles()
172-
{
173-
foreach ($this->files as $filename) {
174-
if (file_exists($filename)) {
175-
@unlink($filename);
176-
}
177-
}
178-
$this->files = array();
179-
}
180176
}

0 commit comments

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