From 692879339d7775980652b63a54d783f746f4a9fb Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 15 Dec 2017 13:24:30 +0100 Subject: [PATCH] Improved the Process component documentation --- components/process.rst | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/components/process.rst b/components/process.rst index 44fa8a26216..566c131dd07 100644 --- a/components/process.rst +++ b/components/process.rst @@ -20,8 +20,11 @@ You can install the component in 2 different ways: Usage ----- -The :class:`Symfony\\Component\\Process\\Process` class allows you to execute -a command in a sub-process:: +The :class:`Symfony\\Component\\Process\\Process` class executes a command in a +sub-process, taking care of the differences between operating system and +escaping arguments to prevent security issues. It replaces PHP functions like +:phpfunction:`exec`, :phpfunction:`passthru`, :phpfunction:`shell_exec` and +:phpfunction:`system`:: use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -36,8 +39,18 @@ a command in a sub-process:: echo $process->getOutput(); -The component takes care of the subtle differences between the different platforms -when executing the command. +.. tip:: + + In addition to passing the command binary and its arguments as a string, you + can also pass them as an array, which is useful when building a complex + command programmatically:: + + // traditional string based commands + $builder = new Process('ls -lsa'); + // same example but using an array + $builder = new Process(array('ls', '-lsa')); + // the array can contain any number of arguments and options + $builder = new Process(array('ls', '-l', '-s', '-a')); The ``getOutput()`` method always returns the whole content of the standard output of the command and ``getErrorOutput()`` the content of the error