Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite8973b5

Browse files
author
Amrouche Hamza
committed
[Process] Allow writing portable "prepared" command lines
1 parenta32b130 commite8973b5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ public function start(callable $callback = null, array $env = array())
278278

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

281-
if ('\\' ===DIRECTORY_SEPARATOR) {
281+
$windows ='\\' ===DIRECTORY_SEPARATOR;
282+
$commandline =$this->replacePlaceholder($commandline,$windows ?array('!','!') :array('$',''));
283+
284+
if ($windows) {
282285
$options['bypass_shell'] =true;
283286
$commandline =$this->prepareWindowsCommandLine($commandline,$envBackup);
284287
}elseif (!$this->useFileHandles &&$this->isSigchildEnabled()) {
@@ -1562,4 +1565,19 @@ private function escapeArgument($argument)
15621565

15631566
return'"'.str_replace(array('"','^','%','!',"\n"),array('""','"^^"','"^%"','"^!"','!LF!'),$argument).'"';
15641567
}
1568+
1569+
privatefunctionreplacePlaceholder($commandLine,$toReplace)
1570+
{
1571+
if (!preg_match_all('/\{([a-zA-Z0-9]+?)\}/',$commandLine,$matches)) {
1572+
return$commandLine;
1573+
}
1574+
1575+
$patterns =$replacements =array();
1576+
foreach ($matchesas$match) {
1577+
$patterns[] =sprintf('/{%s}/',$match[0]);
1578+
$replacements[] =sprintf('%s%s%s',$toReplace[0],$match[0],$toReplace[1]);
1579+
1580+
}
1581+
returnpreg_replace($patterns,$replacements,$commandLine);
1582+
}
15651583
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,18 @@ public function provideEscapeArgument()
14701470
yieldarray('éÉèÈàÀöä');
14711471
}
14721472

1473+
publicfunctiontestWithPreparedCommand()
1474+
{
1475+
$p =newProcess('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
publicfunctiontestEnvArgument()
14741486
{
14751487
$env =array('FOO' =>'Foo','BAR' =>'Bar');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp