@@ -112,7 +112,7 @@ Using Features From the OS Shell
112112
113113Using array of arguments is the recommended way to define commands. This
114114saves 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 escaped value, or will fail if the variable is not found in
151+ the 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+
142157Setting 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-
392386Process Timeout
393387---------------
394388
0 commit comments