@@ -112,7 +112,7 @@ Using Features From the OS Shell
112
112
113
113
Using array of arguments is the recommended way to define commands. This
114
114
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 )::
116
116
117
117
$process = new Process(['/path/command', '--option', 'argument', 'etc.']);
118
118
$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()``,
139
139
// On both Unix-like and Windows
140
140
$process->run(null, ['MESSAGE' => 'Something to output']);
141
141
142
+ To help write command lines that are independent from the operating system,
143
+ you can also write the above code as such::
144
+
10000
tr>
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
+
142
157
Setting Environment Variables for Processes
143
158
-------------------------------------------
144
159
@@ -368,27 +383,6 @@ instead::
368
383
);
369
384
$process->run();
370
385
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
-
392
386
Process Timeout
393
387
---------------
394
388
0 commit comments