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 0d4b75b

Browse filesBrowse files
Update paragraph about portable command lines
1 parent 410acb6 commit 0d4b75b
Copy full SHA for 0d4b75b

File tree

1 file changed

+16
-22
lines changed
Filter options

1 file changed

+16
-22
lines changed

‎components/process.rst

Copy file name to clipboardExpand all lines: components/process.rst
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Using Features From the OS Shell
112112

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

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

142+
To help write command lines that are independent from the operating system,
143+
you can also write the above code as such::
144+
145+
// On both Unix-like and Windows
146+
$process = Process::fromShellCommandline('echo "${:MESSAGE}"');
147+
148+
This requires using a syntax that is specific to the component: when enclosing
149+
a variable name into ``"{$:`` and ``}"`` exactly, the process object will
150+
replace it with its value, or will fail if the variable is not found in the
151+
list of environment variables attached to the command.
152+
153+
.. versionadded:: 4.4
154+
155+
Portable command lines were introduced in Symfony 4.4.
156+
142157
Setting Environment Variables for Processes
143158
-------------------------------------------
144159

@@ -368,27 +383,6 @@ instead::
368383
);
369384
$process->run();
370385

371-
Using a Prepared Command Line
372-
-----------------------------
373-
374-
You can run the process by using a a prepared command line using the
375-
double bracket notation. You can use a placeholder in order to have a
376-
process that can only be changed with the values and without changing
377-
the PHP code::
378-
379-
use Symfony\Component\Process\Process;
380-
381-
$process = Process::fromShellCommandline('echo "$name"');
382-
$process->run(null, ['name' => 'Elsa']);
383-
384-
.. caution::
385-
386-
A prepared command line will not be escaped automatically!
387-
388-
.. versionadded:: 4.4
389-
390-
Prepared command lines were introduced in Symfony 4.4.
391-
392386
Process Timeout
393387
---------------
394388

0 commit comments

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