Skip to content

aurora-php/shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Shell

Execute commands, supports command chaining; proc_open wrapper. Example:

use \Octris\Shell;
use \Octris\Shell\Command;
use \Octris\Shell\StdStream;
use \Octris\Shell\ChunkFilter;

$cmd = Command::HandBrakeCli(['-Z', 'Fast 1080p30', '-i', 'inp.mp4', '-o', 'out.mp4'])
    ->setPipe(StdStream::STDOUT, Command::cat()
        ->appendStreamFilter(StdStream::STDOUT, ChunkFilter::class, function (string $data = null) {
            if (!is_null($data)) {
                if (preg_match('/^Encoding: .+?([0-9]+(\.[0-9]+))\s*%/', trim($data), $match)) {
                    print "\r" . str_repeat(' ', 50);
                    print "\rprogress: " . $match[1] . "%";
                }
            } else {
                print "\r" . str_repeat(' ', 50);
                print "\rprogress: 100%\n";
            }

            return $data;
        }));

Shell::create($cmd)
    ->exec();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages