@@ -20,8 +20,11 @@ You can install the component in 2 different ways:
20
20
Usage
21
21
-----
22
22
23
- The :class: `Symfony\\ Component\\ Process\\ Process ` class allows you to execute
24
- a command in a sub-process::
23
+ The :class: `Symfony\\ Component\\ Process\\ Process ` class executes a command in a
24
+ sub-process, taking care of the differences between operating system and
25
+ escaping arguments to prevent security issues. It replaces PHP functions like
26
+ :phpfunction: `exec `, :phpfunction: `passthru `, :phpfunction: `shell_exec ` and
27
+ :phpfunction: `system `::
25
28
26
29
use Symfony\Component\Process\Process;
27
30
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -36,8 +39,18 @@ a command in a sub-process::
36
39
37
40
echo $process->getOutput();
38
41
39
- The component takes care of the subtle differences between the different platforms
40
- when executing the command.
42
+ .. tip ::
43
+
44
+ In addition to passing the command binary and its arguments as a string, you
45
+ can also pass them as an array, which is useful when building a complex
46
+ command programmatically::
47
+
48
+ // traditional string based commands
49
+ $builder = new Process('ls -lsa');
50
+ // same example but using an array
51
+ $builder = new Process(array('ls', '-lsa'));
52
+ // the array can contain any number of arguments and options
53
+ $builder = new Process(array('ls', '-l', '-s', '-a'));
41
54
42
55
The ``getOutput() `` method always returns the whole content of the standard
43
56
output of the command and ``getErrorOutput() `` the content of the error
0 commit comments