name = $name; $this->info = $_($data,'info'); $this->command = $_($data,'exec'); $this->helper = $_($data,'call'); $this->parser = new Parser($_($data,'parse'), $_($data,'extract')); } public function getName() { return $this->name; } public function getInfo() { return $this->info; } public function setScript(Script $script) { $this->script = $script; } public function execute(array $env, $dialog) { if ($this->helper) { $helper = $this->script->getHelper($this->helper); $helper->call($env); } if (!$this->command) { return; } $cmdl = $this->script->parseVariable($this->command, $env); //printf(" cmd: %s\n", $this->command); //printf(" eval: %s\n", $cmdl); $this->parser->prepareExtractors($this->script, $env); $descr = [ 0 => [ 'pipe', 'r' ], 1 => [ 'pipe', 'w' ], 2 => [ 'pipe', 'w' ] ]; echo "Exec: ".$cmdl."\n"; $proc = proc_open($cmdl, $descr, $pipes); $tot = (int)$env['frames']-1; printf("\r%s [%s]", $this->info, $this->name); $this->parser->parse($pipes, function ($status) use ($tot, $dialog) { $curr = (int)$status['frame']; $pc = min(100,100/$tot*$curr); $dialog->setProgress($pc); $out = sprintf("%s [%s]: %.1f%%", $this->info, $this->name, $pc); $dialog->setText($out); echo "\r{$out}"; }); proc_close($proc); printf("\n"); } }