Skip to content

Commit 278de83

Browse files
committed
feature #3930 [Console] Add Process Helper documentation (romainneutron)
This PR was merged into the master branch. Discussion ---------- [Console] Add Process Helper documentation | Q | A | ------------- | --- | Doc fix? | yes | New docs? | yes (symfony/symfony#10627) | Applies to | 2.5+ | Fixed tickets | n/a This PR replaces #3756 (merged prematurely) Commits ------- a9d6a8b [Console] Add Process Helper documentation
2 parents 907ce67 + a9d6a8b commit 278de83

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

components/console/helpers/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The Console Helpers
99

1010
dialoghelper
1111
formatterhelper
12+
processhelper
1213
progressbar
1314
progresshelper
1415
questionhelper

components/console/helpers/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* :doc:`/components/console/helpers/dialoghelper`
22
* :doc:`/components/console/helpers/formatterhelper`
3+
* :doc:`/components/console/helpers/processhelper`
34
* :doc:`/components/console/helpers/progressbar`
45
* :doc:`/components/console/helpers/progresshelper`
56
* :doc:`/components/console/helpers/questionhelper`
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.. index::
2+
single: Console Helpers; Process Helper
3+
4+
Process Helper
5+
==============
6+
7+
.. versionadded:: 2.6
8+
The Process Helper was introduced in Symfony 2.6.
9+
10+
The Process Helper shows processes as they're running and reports
11+
useful information about process status.
12+
13+
To display process details, use the :class:`Symfony\\Component\\Console\\Helper\\ProcessHelper`
14+
and run your command with verbosity. For example, running the following code with
15+
a very verbose verbosity (e.g. -vv)::
16+
17+
use Symfony\Component\Process\ProcessBuilder;
18+
19+
$helper = $this->getHelper('process');
20+
$process = ProcessBuilder::create(array('figlet', 'Symfony'))->getProcess();
21+
22+
$helper->run($output, $process);
23+
24+
will result in this output:
25+
26+
.. image:: /images/components/console/process-helper-verbose.png
27+
28+
It will result in more detailed output with debug verbosity (e.g. ``-vvv``):
29+
30+
.. image:: /images/components/console/process-helper-debug.png
31+
32+
In case the process fails, debugging is easier:
33+
34+
.. image:: /images/components/console/process-helper-error-debug.png
35+
36+
Arguments
37+
---------
38+
39+
There are three ways to use the process helper:
40+
41+
* Either using a command line string::
42+
43+
// ...
44+
$helper->run($output, 'figlet Symfony');
45+
46+
* An array of arguments::
47+
48+
// ...
49+
$helper->run($output, array('figlet', 'Symfony'));
50+
51+
.. note::
52+
53+
When running the helper against an array of arguments, be aware that
54+
these ones will be automatically escaped.
55+
56+
* Or a :class:`Symfony\\Component\\Process\\Process` instance::
57+
58+
use Symfony\Component\Process\ProcessBuilder;
59+
60+
// ...
61+
$process = ProcessBuilder::create(array('figlet', 'Symfony'))->getProcess();
62+
63+
$helper->run($output, $process);
64+
65+
Customized Display
66+
------------------
67+
68+
You can display a customized error message using the third argument of the
69+
:method:`Symfony\\Component\\Console\\Helper\\ProcessHelper::run` method::
70+
71+
$helper->run($output, $process, 'The process failed :(');
72+
73+
A custom process callback can be passed as fourth argument, refer to the
74+
:doc:`Process Component </components/process>` for callback documentation::
75+
76+
use Symfony\Component\Process\Process;
77+
78+
$helper->run($output, $process, 'The process failed :(', function ($type, $data) {
79+
if (Process::ERR === $type) {
80+
// ... do something with the stderr output
81+
} else {
82+
// ... do something with the stdout
83+
}
84+
});
Loading
Loading
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy