Skip to content

Commit e8a1501

Browse files
committed
feature #4201 [Components][Process] mustRun() documentation (xabbuh)
This PR was submitted for the master branch but it was merged into the 2.5 branch instead (closes #4201). Discussion ---------- [Components][Process] `mustRun()` documentation | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#8655) | Applies to | 2.5+ | Fixed tickets | #4187 @weaverryan Sorry, this should be merged into 2.5. Commits ------- ad6a340 [Components][Process] `mustRun()` documentation
2 parents 8c9847d + ad6a340 commit e8a1501

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 numberOriginal file lineDiff line numberDiff line change
@@ -31,7 +31,7 @@ a command in a sub-process::
31
throw new \RuntimeException($process->getErrorOutput());
31
throw new \RuntimeException($process->getErrorOutput());
32
}
32
}
33

33

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

35

36
The component takes care of the subtle differences between the different platforms
36
The component takes care of the subtle differences between the different platforms
37
when executing the command.
37
when executing the command.
@@ -50,6 +50,27 @@ the contents of the output and
50
:method:`Symfony\\Component\\Process\\Process::clearErrorOutput` clears
50
:method:`Symfony\\Component\\Process\\Process::clearErrorOutput` clears
51
the contents of the error output.
51
the contents of the error output.
52

52

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+
53
Getting real-time Process Output
74
Getting real-time Process Output
54
--------------------------------
75
--------------------------------
55

76

@@ -218,17 +239,17 @@ Process Idle Timeout
218
.. versionadded:: 2.4
239
.. versionadded:: 2.4
219
The :method:`Symfony\\Component\\Process\\Process::setIdleTimeout` method
240
The :method:`Symfony\\Component\\Process\\Process::setIdleTimeout` method
220
was introduced in Symfony 2.4.
241
was introduced in Symfony 2.4.
221-
242+
222
In contrast to the timeout of the previous paragraph, the idle timeout only
243
In contrast to the timeout of the previous paragraph, the idle timeout only
223
considers the time since the last output was produced by the process::
244
considers the time since the last output was produced by the process::
224

245

225
use Symfony\Component\Process\Process;
246
use Symfony\Component\Process\Process;
226-
247+
227
$process = new Process('something-with-variable-runtime');
248
$process = new Process('something-with-variable-runtime');
228
$process->setTimeout(3600);
249
$process->setTimeout(3600);
229
$process->setIdleTimeout(60);
250
$process->setIdleTimeout(60);
230
$process->run();
251
$process->run();
231-
252+
232
In the case above, a process is considered timed out, when either the total runtime
253
In the case above, a process is considered timed out, when either the total runtime
233
exceeds 3600 seconds, or the process does not produce any output for 60 seconds.
254
exceeds 3600 seconds, or the process does not produce any output for 60 seconds.
234

255

0 commit comments

Comments
 (0)