Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update paragraph about portable command lines #12772

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

Merged
merged 1 commit into from
Dec 20, 2019
Merged
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
38 changes: 16 additions & 22 deletions components/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Using Features From the OS Shell

Using array of arguments is the recommended way to define commands. This
saves you from any escaping and allows sending signals seamlessly
(e.g. to stop processes before completion)::
(e.g. to stop processes while they run)::

$process = new Process(['/path/command', '--option', 'argument', 'etc.']);
$process = new Process(['/path/to/php', '--define', 'memory_limit=1024M', '/path/to/script.php']);
Expand All @@ -139,6 +139,21 @@ environment variables using the second argument of the ``run()``,
// On both Unix-like and Windows
$process->run(null, ['MESSAGE' => 'Something to output']);

To help write command lines that are independent from the operating system,
you can also write the above code as such::

// On both Unix-like and Windows
$process = Process::fromShellCommandline('echo "${:MESSAGE}"');

This requires using a syntax that is specific to the component: when enclosing
a variable name into ``"{$:`` and ``}"`` exactly, the process object will
replace it with its escaped value, or will fail if the variable is not found in
the list of environment variables attached to the command.

.. versionadded:: 4.4

Portable command lines were introduced in Symfony 4.4.

Setting Environment Variables for Processes
-------------------------------------------

Expand Down Expand Up @@ -368,27 +383,6 @@ instead::
);
$process->run();

Using a Prepared Command Line
-----------------------------

You can run the process by using a a prepared command line using the
double bracket notation. You can use a placeholder in order to have a
process that can only be changed with the values and without changing
the PHP code::

use Symfony\Component\Process\Process;

$process = Process::fromShellCommandline('echo "$name"');
$process->run(null, ['name' => 'Elsa']);

.. caution::

A prepared command line will not be escaped automatically!

.. versionadded:: 4.4

Prepared command lines were introduced in Symfony 4.4.

Process Timeout
---------------

Expand Down