Skip to content

Added a short section about "Setting Environment Variables for Processes" #10983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ 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 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']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need both lines?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're trying to display multiple different ways to set up env vars. Thats's why we have several lines.

$process->run(null, ['ENV_VAR_NAME' => 'value']);

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,
]);

Getting real-time Process Output
--------------------------------

Expand Down