Skip to content

Commit

Permalink
feature #4201 [Components][Process] mustRun() documentation (xabbuh)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
weaverryan committed Oct 1, 2014
2 parents 8c9847d + ad6a340 commit e8a1501
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions components/process.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ a command in a sub-process::
throw new \RuntimeException($process->getErrorOutput()); throw new \RuntimeException($process->getErrorOutput());
} }


print $process->getOutput(); echo $process->getOutput();


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


.. versionadded:: 2.5
The ``mustRun()`` method was introduced in Symfony 2.5.

The ``mustRun()`` method is identical to ``run()``, except that it will throw
a :class:`Symfony\\Component\\Process\\Exception\\ProcessFailedException`
if the process couldn't be executed successfully (i.e. the process exited
with a non-zero code)::

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

$process = new Process('ls -lsa');

try {
$process->mustRun();

echo $process->getOutput();
} catch (ProcessFailedException $e) {
echo $e->getMessage();
}

Getting real-time Process Output Getting real-time Process Output
-------------------------------- --------------------------------


Expand Down Expand Up @@ -218,17 +239,17 @@ Process Idle Timeout
.. versionadded:: 2.4 .. versionadded:: 2.4
The :method:`Symfony\\Component\\Process\\Process::setIdleTimeout` method The :method:`Symfony\\Component\\Process\\Process::setIdleTimeout` method
was introduced in Symfony 2.4. was introduced in Symfony 2.4.

In contrast to the timeout of the previous paragraph, the idle timeout only In contrast to the timeout of the previous paragraph, the idle timeout only
considers the time since the last output was produced by the process:: considers the time since the last output was produced by the process::


use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;

$process = new Process('something-with-variable-runtime'); $process = new Process('something-with-variable-runtime');
$process->setTimeout(3600); $process->setTimeout(3600);
$process->setIdleTimeout(60); $process->setIdleTimeout(60);
$process->run(); $process->run();

In the case above, a process is considered timed out, when either the total runtime In the case above, a process is considered timed out, when either the total runtime
exceeds 3600 seconds, or the process does not produce any output for 60 seconds. exceeds 3600 seconds, or the process does not produce any output for 60 seconds.


Expand Down

0 comments on commit e8a1501

Please sign in to comment.