From 6bbd4b8eeb6c43e4f1ddc860202ac21d947a63d6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 11 Feb 2019 13:38:51 +0100 Subject: [PATCH 1/2] Added a short section about "Setting Environment Variables for Processes" --- components/process.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/components/process.rst b/components/process.rst index 2422267bd8c..440d3d42d4e 100644 --- a/components/process.rst +++ b/components/process.rst @@ -128,6 +128,28 @@ environment variables using the second argument of the ``run()``, // On both Unix-like and Windows $process->run(null, ['MESSAGE' => 'Something to output']); +Setting Environment Variables for Processes +------------------------------------------- + +The constructor of the :class:`Symfony\\Component\\Process\\Process` class and +all its methods related to executing processes (``run()``, ``mustRun()``, +``start()``, etc.) allow passing an array of environment variables to set before +running the process:: + + $process = new Process(['...'], null, ['ENV_VAR_NAME' => 'value']); + $process = Process::fromShellCommandline('...', null, ['ENV_VAR_NAME' => 'value']); + $process->run(null, ['ENV_VAR_NAME' => 'value']); + // ... + +These environment variables are automatically inherited by child processes. You +can prevent that setting the following env vars to ``false``:: + + // ... + $process = new Process(['...'], null, [ + 'APP_ENV' => false, + 'SYMFONY_DOTENV_VARS' => false + ]); + Getting real-time Process Output -------------------------------- From 69547447fbb283012a562b127bd154907d41b1c2 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 20 Feb 2019 09:52:32 +0100 Subject: [PATCH 2/2] Fixes after the reviewers review --- components/process.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/process.rst b/components/process.rst index 440d3d42d4e..9a6f0055bdd 100644 --- a/components/process.rst +++ b/components/process.rst @@ -132,22 +132,21 @@ Setting Environment Variables for Processes ------------------------------------------- The constructor of the :class:`Symfony\\Component\\Process\\Process` class and -all its methods related to executing processes (``run()``, ``mustRun()``, -``start()``, etc.) allow passing an array of environment variables to set before +all of its methods related to executing processes (``run()``, ``mustRun()``, +``start()``, etc.) allow passing an array of environment variables to set while running the process:: $process = new Process(['...'], null, ['ENV_VAR_NAME' => 'value']); $process = Process::fromShellCommandline('...', null, ['ENV_VAR_NAME' => 'value']); $process->run(null, ['ENV_VAR_NAME' => 'value']); - // ... -These environment variables are automatically inherited by child processes. You -can prevent that setting the following env vars to ``false``:: +In addition to the env vars passed explicitly, processes inherit all the env +vars defined in your system. You can prevent this by setting to ``false`` the +env vars you want to remove:: - // ... $process = new Process(['...'], null, [ 'APP_ENV' => false, - 'SYMFONY_DOTENV_VARS' => false + 'SYMFONY_DOTENV_VARS' => false, ]); Getting real-time Process Output