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

Appearance settings

Commit bf1c431

Browse filesBrowse files
committed
minor #10983 Added a short section about "Setting Environment Variables for Processes" (javiereguiluz)
This PR was squashed before being merged into the 4.2 branch (closes #10983). Discussion ---------- Added a short section about "Setting Environment Variables for Processes" Fixes #10967. Commits ------- 91697b8 Added a short section about \"Setting Environment Variables for Processes\"
2 parents 7cd23ce + 91697b8 commit bf1c431
Copy full SHA for bf1c431

File tree

1 file changed

+21
-0
lines changed
Filter options

1 file changed

+21
-0
lines changed

‎components/process.rst

Copy file name to clipboardExpand all lines: components/process.rst
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ environment variables using the second argument of the ``run()``,
128128
// On both Unix-like and Windows
129129
$process->run(null, ['MESSAGE' => 'Something to output']);
130130

131+
Setting Environment Variables for Processes
132+
-------------------------------------------
133+
134+
The constructor of the :class:`Symfony\\Component\\Process\\Process` class and
135+
all of its methods related to executing processes (``run()``, ``mustRun()``,
136+
``start()``, etc.) allow passing an array of environment variables to set while
137+
running the process::
138+
139+
$process = new Process(['...'], null, ['ENV_VAR_NAME' => 'value']);
140+
$process = Process::fromShellCommandline('...', null, ['ENV_VAR_NAME' => 'value']);
141+
$process->run(null, ['ENV_VAR_NAME' => 'value']);
142+
143+
In addition to the env vars passed explicitly, processes inherit all the env
144+
vars defined in your system. You can prevent this by setting to ``false`` the
145+
env vars you want to remove::
146+
147+
$process = new Process(['...'], null, [
148+
'APP_ENV' => false,
149+
'SYMFONY_DOTENV_VARS' => false,
150+
]);
151+
131152
Getting real-time Process Output
132153
--------------------------------
133154

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.