8000 minor #16269 [Process] tweaked README (fabpot) · symfony/symfony@8b3922a · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b3922a

Browse files
committed
minor #16269 [Process] tweaked README (fabpot)
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #16269). Discussion ---------- [Process] tweaked README | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16216 | License | MIT | Doc PR | n/a Commits ------- 11622ad [Process] tweaked README
2 parents 6e6a0ba + 11622ad commit 8b3922a

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