8000 [Process] tweaked README · symfony/symfony@11622ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 11622ad

Browse files
committed
[Process] tweaked README
1 parent 6e6a0ba commit 11622ad

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Symfony/Component/Process/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ In this example, we run a simple directory listing and get the result back:
77

88
```php
99
use Symfony\Component\Process\Process;
10+
use Symfony\Component\Process\Exception\ProcessFailedException;
1011

1112
$process = new Process('ls -lsa');
1213
$process->setTimeout(3600);
1314
$process->run();
1415
if (!$process->isSuccessful()) {
15-
throw new RuntimeException($process->getErrorOutput());
16+
throw new ProcessFailedException($process);
1617
}
1718

1819
print $process->getOutput();
@@ -21,6 +22,19 @@ print $process->getOutput();
2122
You can think that this is easy to achieve with plain PHP but it's not especially
2223
if you want to take care of the subtle differences between the different platforms.
2324

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+
2438
And if you want to be able to get some feedback in real-time, just pass an
2539
anonymous function to the ``run()`` method and you will get the output buffer
2640
as it becomes available:

0 commit comments

Comments
 (0)
0