Нет описания https://symfony.com/components/Process

Fabien Potencier 2756ff2bc8 Merge branch '2.3' into 2.4 10 лет назад
Exception 225f6e85fb fixed CS 11 лет назад
Tests 2756ff2bc8 Merge branch '2.3' into 2.4 10 лет назад
.gitignore 8ac46d268d Added missing files .gitignore 11 лет назад
CHANGELOG.md c40a7806f9 [Process] updated the CHANGELOG 11 лет назад
ExecutableFinder.php cf09eaf9a0 [Process] Fixes issue #11421 10 лет назад
LICENSE 2c19ffff12 update year on licenses 11 лет назад
PhpExecutableFinder.php 61b85c3e6a Use separated function to resolve command and related arguments 10 лет назад
PhpProcess.php 26893524a0 made phpdoc types consistent with those defined in Hack 10 лет назад
Process.php 6a2bd3d624 Merge branch '2.3' into 2.4 10 лет назад
ProcessBuilder.php 78f1e56bb1 add missing docblock for ProcessBuilder::addEnvironmentVariables() 10 лет назад
ProcessPipes.php 35c2a047a3 bug #11120 [2.3][Process] Reduce I/O load on Windows platform (romainneutron) 10 лет назад
ProcessUtils.php 2cd7d075df [Process] Add validation on Process input 10 лет назад
README.md 700bbb5e48 [Process] Minor README update 10 лет назад
composer.json 75c810176f updated version to 2.4 11 лет назад
phpunit.xml.dist 6e70dd4051 removed defaults from PHPUnit configuration 10 лет назад

README.md

Process Component

Process executes commands in sub-processes.

In this example, we run a simple directory listing and get the result back:

use Symfony\Component\Process\Process;

$process = new Process('ls -lsa');
$process->setTimeout(3600);
$process->run();
if (!$process->isSuccessful()) {
    throw new RuntimeException($process->getErrorOutput());
}

print $process->getOutput();

You can think that this is easy to achieve with plain PHP but it's not especially if you want to take care of the subtle differences between the different platforms.

And if you want to be able to get some feedback in real-time, just pass an anonymous function to the run() method and you will get the output buffer as it becomes available:

use Symfony\Component\Process\Process;

$process = new Process('ls -lsa');
$process->run(function ($type, $buffer) {
    if (Process::ERR === $type) {
        echo 'ERR > '.$buffer;
    } else {
        echo 'OUT > '.$buffer;
    }
});

That's great if you want to execute a long running command (like rsync-ing files to a remote server) and give feedback to the user in real-time.

Resources

You can run the unit tests with the following command:

$ cd path/to/Symfony/Component/Process/
$ composer.phar install
$ phpunit