8000 minor #10659 Update doc for Process v4.2 (nicolas-grekas) · symfony/symfony-docs@db13bd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit db13bd9

Browse files
committed
minor #10659 Update doc for Process v4.2 (nicolas-grekas)
This PR was merged into the master branch. Discussion ---------- Update doc for Process v4.2 Follows symfony/symfony#27821 Fixes #10299 Commits ------- 3a0a450 Update doc for Process v4.2
2 parents 1c4a8d0 + 3a0a450 commit db13bd9

File tree

1 file changed

+25
-36
lines changed

1 file changed

+25
-36
lines changed

components/process.rst

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ escaping arguments to prevent security issues. It replaces PHP functions like
4040

4141
echo $process->getOutput();
4242

43-
.. tip::
44-
45-
In addition to passing the command binary and its arguments as a string, you
46-
can also pass them as an array, which is useful when building a complex
47-
command programmatically::
48-
49-
// traditional string based commands
50-
$builder = new Process('ls -lsa');
51-
// same example but using an array
52-
$builder = new Process(array('ls', '-lsa'));
53-
// the array can contain any number of arguments and options
54-
$builder = new Process(array('ls', '-l', '-s', '-a'));
55-
5643
The ``getOutput()`` method always returns the whole content of the standard
5744
output of the command and ``getErrorOutput()`` the content of the error
5845
output. Alternatively, the :method:`Symfony\\Component\\Process\\Process::getIncrementalOutput`
@@ -110,37 +97,39 @@ with a non-zero code)::
11097
echo $exception->getMessage();
11198
}
11299

113-
.. tip::
100+
Using features from the OS shell
101+
--------------------------------
114102

115-
.. versionadded:: 3.3
116-
The ability to define commands as arrays of arguments was introduced in
117-
Symfony 3.3.
103+
.. versionadded:: 4.2
104+
The ``fromShellCommandline()`` static method was introduced in Symfony 4.2.
118105

119-
Using array of arguments is the recommended way to define commands. This
120-
saves you from any escaping and allows sending signals seamlessly
121-
(e.g. to stop processes before completion.)::
106+
Using array of arguments is the recommended way to define commands. This
107+
saves you from any escaping and allows sending signals seamlessly
108+
(e.g. to stop processes before completion.)::
122109

123-
$process = new Process(array('/path/command', '--flag', 'arg 1', 'etc.'));
110+
$process = new Process(array('/path/command', '--flag', 'arg 1', 'etc.'));
124111

125-
If you need to use stream redirections, conditional execution, or any other
126-
feature provided by the shell of your operating system, you can also define
127-
commands as strings.
112+
If you need to use stream redirections, conditional execution, or any other
113+
feature provided by the shell of your operating system, you can also define
114+
commands as strings using the
115+
:method:`Symfony\\Component\\Process\\Process::fromShellCommandline` static
116+
factory.
128117

129-
Please note that each OS provides a different syntax for their command-lines
130-
so that it becomes your responsibility to deal with escaping and portability.
118+
Please note that each OS provides a different syntax for their command-lines
119+
so that it becomes your responsibility to deal with escaping and portability.
131120

132-
To provide any variable arguments to command-line string, pass them as
133-
environment variables using the second argument of the ``run()``,
134-
``mustRun()`` or ``start()`` methods. Referencing them is also OS-dependent::
121+
To provide any variable arguments to command-line string, pass them as
122+
environment variables using the second argument of the ``run()``,
123+
``mustRun()`` or ``start()`` methods. Referencing them is also OS-dependent::
135124

136-
// On Unix-like OSes (Linux, macOS)
137-
$process = new Process('echo "$MESSAGE"');
125+
// On Unix-like OSes (Linux, macOS)
126+
$process = Process::fromShellCommandline('echo "$MESSAGE"');
138127

139-
// On Windows
140-
$process = new Process('echo "!MESSAGE!"');
128+
// On Windows
129+
$process = Process::fromShellCommandline('echo "!MESSAGE!"');
141130

142-
// On both Unix-like and Windows
143-
$process->run(null, array('MESSAGE' => 'Something to output'));
131+
// On both Unix-like and Windows
132+
$process->run(null, array('MESSAGE' => 'Something to output'));
144133

145134
Getting real-time Process Output
146135
--------------------------------
@@ -261,7 +250,7 @@ Before a process is started, you can specify its standard input using either the
261250
of the constructor. The provided input can be a string, a stream resource or a
262251
Traversable object::
263252

264-
$process = new Process('cat');
253+
$process = new Process(array('cat'));
265254
$process->setInput('foobar');
266255
$process->run();
267256

0 commit comments

Comments
 (0)
0