File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
src/Symfony/Component/Process Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,13 @@ In this example, we run a simple directory listing and get the result back:
7
7
8
8
``` php
9
9
use Symfony\Component\Process\Process;
10
+ use Symfony\Component\Process\Exception\ProcessFailedException;
10
11
11
12
$process = new Process('ls -lsa');
12
13
$process->setTimeout(3600);
13
14
$process->run();
14
15
if (!$process->isSuccessful()) {
15
- throw new RuntimeException ($process->getErrorOutput() );
16
+ throw new ProcessFailedException ($process);
16
17
}
17
18
18
19
print $process->getOutput();
@@ -21,6 +22,19 @@ print $process->getOutput();
21
22
You can think that this is easy to achieve with plain PHP but it's not especially
22
23
if you want to take care of the subtle differences between the different platforms.
23
24
25
+ You can simplify the code by using ` mustRun() ` instead of ` run() ` , which will
26
+ throw a ` ProcessFailedException ` automatically in case of a problem:
27
+
28
+ ``` php
29
+ use Symfony\Component\Process\Process;
30
+
31
+ $process = new Process('ls -lsa');
32
+ $process->setTimeout(3600);
33
+ $process->mustRun();
34
+
35
+ print $process->getOutput();
36
+ ```
37
+
24
38
And if you want to be able to get some feedback in real-time, just pass an
25
39
anonymous function to the `` run() `` method and you will get the output buffer
26
40
as it becomes available:
You can’t perform that action at this time.
0 commit comments