Skip to content

Commit 6928793

Browse files
committed
Improved the Process component documentation
1 parent 13d112b commit 6928793

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

components/process.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ You can install the component in 2 different ways:
2020
Usage
2121
-----
2222

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`::
2528

2629
use Symfony\Component\Process\Process;
2730
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -36,8 +39,18 @@ a command in a sub-process::
3639

3740
echo $process->getOutput();
3841

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'));
4154

4255
The ``getOutput()`` method always returns the whole content of the standard
4356
output of the command and ``getErrorOutput()`` the content of the error

0 commit comments

Comments
 (0)