8000 [Components][Process] `mustRun()` documentation · symfony/symfony-docs@ad6a340 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ad6a340

Browse files
xabbuhweaverryan
authored andcommitted
[Components][Process] mustRun() documentation
1 parent 8c9847d commit ad6a340

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

components/process.rst

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ a command in a sub-process::
3131
throw new \RuntimeException($process->getErrorOutput());
3232
}
3333

34-
print $process->getOutput();
34+
echo $process->getOutput();
3535

3636
The component takes care of the subtle differences between the different platforms
3737
when executing the command.
@@ -50,6 +50,27 @@ the contents of the output and
5050
:method:`Symfony\\Component\\Process\\Process::clearErrorOutput` clears
5151
the contents of the error output.
5252

53+
.. versionadded:: 2.5
54+
The ``mustRun()`` method was introduced in Symfony 2.5.
55+
56+
The ``mustRun()`` method is identical to ``run()``, except that it will throw
57+
a :class:`Symfony\\Component\\Process\\Exception\\ProcessFailedException`
58+
if the process couldn't be executed successfully (i.e. the process exited
59+
with a non-zero code)::
60+
61+
use Symfony\Component\Process\Exception\ProcessFailedException;
62+
use Symfony\Component\Process\Process;
63+
64+
$process = new Process('ls -lsa');
65+
66+
try {
67+
$process->mustRun();
68+
69+
echo $process->getOutput();
70+
} catch (ProcessFailedException $e) {
71+
echo $e->getMessage();
72+
}
73+
5374
Getting real-time Process Output
5475
--------------------------------
5576

@@ -218,17 +239,17 @@ Process Idle Timeout
218239
.. versionadded:: 2.4
219240
The :method:`Symfony\\Component\\Process\\Process::setIdleTimeout` method
220241
was introduced in Symfony 2.4.
221-
242+
222243
In contrast to the timeout of the previous paragraph, the idle timeout only
223244
considers the time since the last output was produced by the process::
224245

225246
use Symfony\Component\Process\Process;
226-
247+
227248
$process = new Process('something-with-variable-runtime');
228249
$process->setTimeout(3600);
229250
$process->setIdleTimeout(60);
230251
$process->run();
231-
252+
232253
In the case above, a process is considered timed out, when either the total runtime
233254
exceeds 3600 seconds, or the process does not produce any output for 60 seconds.
234255

0 commit comments

Comments
 (0)
0