-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 | ||||||
javiereguiluz marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
running the process:: | ||||||
|
||||||
$process = new Process(['...'], null, ['ENV_VAR_NAME' => 'value']); | ||||||
$process = Process::fromShellCommandline('...', null, ['ENV_VAR_NAME' => 'value']); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need both lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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']); | ||||||
// ... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo this is only noise |
||||||
|
||||||
These environment variables are automatically inherited by child processes. You | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These environment variables and the already existing environment variables bound to the current process are inherited by child processes. You can hide an environment variable from child processes by setting it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need some help trying to understand this in practice. Imagine this command: $process = new Process(['foo'], null, ['APP_ENV' => 'test']);
But here we are saying, if you want to prevent that, set the env var to $process = new Process(['foo'], null, ['APP_ENV' => false]); OK, so child processes now don't use Question: how can I define an env var for a command ... and prevent defining it for its child processes? Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now I understand. Thanks! |
||||||
can prevent that setting the following env vars to ``false``:: | ||||||
javiereguiluz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// ... | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo this is only noise |
||||||
$process = new Process(['...'], null, [ | ||||||
'APP_ENV' => false, | ||||||
'SYMFONY_DOTENV_VARS' => false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you keep this, you should add this:
Suggested change
|
||||||
]); | ||||||
|
||||||
javiereguiluz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Getting real-time Process Output | ||||||
-------------------------------- | ||||||
|
||||||
|
Uh oh!
There was an error while loading. Please reload this page.