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 2c23e96

Browse filesBrowse files
author
Amrouche Hamza
committed
[Process] Allow writing portable "prepared" command lines
1 parent a32b130 commit 2c23e96
Copy full SHA for 2c23e96

File tree

2 files changed

+26
-0
lines changed
Filter options

2 files changed

+26
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,13 @@ public function start(callable $callback = null, array $env = array())
278278

279279
$options = array('suppress_errors' => true);
280280

281+
if ('\\' !== DIRECTORY_SEPARATOR) {
282+
$commandline = $this->replacePlaceholder($commandline, array('$', ''));
283+
}
284+
281285
if ('\\' === DIRECTORY_SEPARATOR) {
282286
$options['bypass_shell'] = true;
287+
$commandline = $this->replacePlaceholder($commandline, array('!', '!'));
283288
$commandline = $this->prepareWindowsCommandLine($commandline, $envBackup);
284289
} elseif (!$this->useFileHandles && $this->isSigchildEnabled()) {
285290
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
@@ -1562,4 +1567,13 @@ private function escapeArgument($argument)
15621567

15631568
return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
15641569
}
1570+
1571+
private function replacePlaceholder($commandLine, $toReplace)
1572+
{
1573+
if (preg_match('/\{([a-zA-Z0-9]*?)\}/', $commandLine)) {
1574+
return str_replace(array('{', '}'), $toReplace, $commandLine);
1575+
}
1576+
1577+
return $commandLine;
1578+
}
15651579
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/ProcessTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,18 @@ public function provideEscapeArgument()
14701470
yield array('éÉèÈàÀöä');
14711471
}
14721472

1473+
public function testWithPreparedCommand()
1474+
{
1475+
$p = new Process('echo {abc}');
1476+
$p->run(null, array('abc' => 'ABC'));
1477+
1478+
$expected = <<<EOTXT
1479+
ABC
1480+
1481+
EOTXT;
1482+
$this->assertSame($expected, $p->getOutput());
1483+
}
1484+
14731485
public function testEnvArgument()
14741486
{
14751487
$env = array('FOO' => 'Foo', 'BAR' => 'Bar');

0 commit comments

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