8000 bug #19118 [Process] Fix pipes cleaning on Windows (nicolas-grekas) · symfony/symfony@ec19a52 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec19a52

Browse files
committed
bug #19118 [Process] Fix pipes cleaning on Windows (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [Process] Fix pipes cleaning on Windows | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19089 | License | MIT | Doc PR | - Commits ------- d54cd02 [Process] Fix pipes cleaning on Windows
2 parents a65fe45 + d54cd02 commit ec19a52

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines 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

Lines 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 551B ) {
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