Mike42\Escpos\PrintConnectors\CupsPrintConnector::getCmdOutput PHP Method

getCmdOutput() protected method

(Basically exec() with good error handling)
protected getCmdOutput ( string $cmd )
$cmd string Command to run
    protected function getCmdOutput($cmd)
    {
        $descriptors = array(1 => array("pipe", "w"), 2 => array("pipe", "w"));
        $process = proc_open($cmd, $descriptors, $fd);
        if (!is_resource($process)) {
            throw new Exception("Command '{$cmd}' failed to start.");
        }
        /* Read stdout */
        $outputStr = stream_get_contents($fd[1]);
        fclose($fd[1]);
        /* Read stderr */
        $errorStr = stream_get_contents($fd[2]);
        fclose($fd[2]);
        /* Finish up */
        $retval = proc_close($process);
        if ($retval != 0) {
            throw new Exception("Command {$cmd} failed: {$errorStr}");
        }
        return $outputStr;
    }