@@ -320,7 +320,7 @@ public function start(callable $callback = null/*, array $env = array()*/)
320
320
}
321
321
if ('\\' === DIRECTORY_SEPARATOR && $ this ->enhanceWindowsCompatibility ) {
322
322
$ this ->options ['bypass_shell ' ] = true ;
323
- $ commandline = $ this ->prepareWindowsCommandLine ($ commandline , $ envBackup );
323
+ $ commandline = $ this ->prepareWindowsCommandLine ($ commandline , $ envBackup, $ env );
324
324
} elseif (!$ this ->useFileHandles && $ this ->enhanceSigchildCompatibility && $ this ->isSigchildEnabled ()) {
325
325
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
326
326
$ descriptors [3 ] = array ('pipe ' , 'w ' );
@@ -1627,7 +1627,7 @@ private function doSignal($signal, $throwException)
1627
1627
return true ;
1628
1628
}
1629
1629
1630
- private function prepareWindowsCommandLine ($ cmd , array &$ envBackup )
1630
+ private function prepareWindowsCommandLine ($ cmd , array &$ envBackup, array & $ env = null )
1631
1631
{
1632
1632
$ uid = uniqid ('' , true );
1633
1633
$ varCount = 0 ;
@@ -1640,7 +1640,7 @@ private function prepareWindowsCommandLine($cmd, array &$envBackup)
1640
1640
[^"%!^]*+
1641
1641
)++
1642
1642
)"/x ' ,
1643
- function ($ m ) use (&$ envBackup , &$ varCache , &$ varCount , $ uid ) {
1643
+ function ($ m ) use (&$ envBackup , &$ env , & $ varCache , &$ varCount , $ uid ) {
1644
1644
if (isset ($ varCache [$ m [0 ]])) {
1645
1645
return $ varCache [$ m [0 ]];
1646
1646
}
@@ -1652,10 +1652,15 @@ function ($m) use (&$envBackup, &$varCache, &$varCount, $uid) {
1652
1652
}
1653
1653
1654
1654
$ value = str_replace (array ('!LF! ' , '"^!" ' , '"^%" ' , '"^^" ' , '"" ' ), array ("\n" , '! ' , '% ' , '^ ' , '" ' ), $ value );
1655
- $ value = preg_replace ('/( \\\\*)"/ ' , '$1$1 \\" ' , $ value );
1656
-
1655
+ $ value = '" ' .preg_replace ('/( \\\\*)"/ ' , '$1$1 \\" ' , $ value ).'" ' ;
1657
1656
$ var = $ uid .++$ varCount ;
1658
- putenv ("$ var= \"$ value \"" );
1657
+
1658
+ if (null === $ env ) {
1659
+ putenv ("$ var= $ value " );
1660
+ } else {
1661
+ $ env [$ var ] = $ value ;
1662
+ }
1663
+
1659
1664
$ envBackup [$ var ] = false ;
1660
1665
1661
1666
return $ varCache [$ m [0 ]] = '! ' .$ var .'! ' ;
0 commit comments