@@ -266,24 +266,25 @@ public function start(callable $callback = null)
266266$ this ->callback =$ this ->buildCallback ($ callback );
267267$ this ->hasCallback =null !==$ callback ;
268268$ descriptors =$ this ->getDescriptors ();
269+ $ inheritEnv =$ this ->inheritEnv ;
269270
270271$ commandline =$ this ->commandline ;
271- $ envline ='' ;
272272
273- if (null !==$ this ->env &&$ this ->inheritEnv ) {
273+ $ env =$ this ->env ;
274+ $ envBackup =array ();
275+ if (null !==$ env &&$ inheritEnv ) {
274276if ('\\' ===DIRECTORY_SEPARATOR && !empty ($ this ->options ['bypass_shell ' ]) && !$ this ->enhanceWindowsCompatibility ) {
275277throw new LogicException ('The "bypass_shell" option must be false to inherit environment variables while enhanced Windows compatibility is off ' );
276278 }
277- $ env ='\\' ===DIRECTORY_SEPARATOR ?'(SET %s)&& ' :'export %s; ' ;
278- foreach ($ this ->env as $ k =>$ v ) {
279- $ envline .=sprintf ($ env , ProcessUtils::escapeArgument ("$ k= $ v " ));
279+
280+ foreach ($ envas $ k =>$ v ) {
281+ $ envBackup [$ k ] =getenv ($ v );
282+ putenv (false ===$ v ||null ===$ v ?$ k :"$ k= $ v " );
280283 }
281284$ env =null ;
282- }else {
283- $ env =$ this ->env ;
284285 }
285286if ('\\' ===DIRECTORY_SEPARATOR &&$ this ->enhanceWindowsCompatibility ) {
286- $ commandline ='cmd /V:ON /E:ON /D /C "( ' .$ envline . $ commandline .') ' ;
287+ $ commandline ='cmd /V:ON /E:ON /D /C "( ' .$ commandline .') ' ;
287288foreach ($ this ->processPipes ->getFiles ()as $ offset =>$ filename ) {
288289$ commandline .=' ' .$ offset .'> ' .ProcessUtils::escapeArgument ($ filename );
289290 }
@@ -297,18 +298,20 @@ public function start(callable $callback = null)
297298$ descriptors [3 ] =array ('pipe ' ,'w ' );
298299
299300// See https://unix.stackexchange.com/questions/71205/background-process-pipe-input
300- $ commandline =$ envline . '{ ( ' .$ this ->commandline .') <&3 3<&- 3>/dev/null & } 3<&0; ' ;
301+ $ commandline ='{ ( ' .$ this ->commandline .') <&3 3<&- 3>/dev/null & } 3<&0; ' ;
301302$ commandline .='pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code ' ;
302303
303304// Workaround for the bug, when PTS functionality is enabled.
304305// @see : https://bugs.php.net/69442
305306$ ptsWorkaround =fopen (__FILE__ ,'r ' );
306- }elseif ('' !==$ envline ) {
307- $ commandline =$ envline .$ commandline ;
308307 }
309308
310309$ this ->process =proc_open ($ commandline ,$ descriptors ,$ this ->processPipes ->pipes ,$ this ->cwd ,$ env ,$ this ->options );
311310
311+ foreach ($ envBackupas $ k =>$ v ) {
312+ putenv (false ===$ v ?$ k :"$ k= $ v " );
313+ }
314+
312315if (!is_resource ($ this ->process )) {
313316throw new RuntimeException ('Unable to launch a new process. ' );
314317 }
@@ -1099,15 +1102,7 @@ public function getEnv()
10991102 */
11001103public function setEnv (array $ env )
11011104 {
1102- // Process can not handle env values that are arrays
1103- $ env =array_filter ($ env ,function ($ value ) {
1104- return !is_array ($ value );
1105- });
1106-
1107- $ this ->env =array ();
1108- foreach ($ envas $ key =>$ value ) {
1109- $ this ->env [$ key ] = (string )$ value ;
1110- }
1105+ $ this ->env =$ env ;
11111106
11121107return $ this ;
11131108 }