ob_start(); exec($cmd . " 2>&1", $output); $result = ob_get_contents(); ob_end_clean(); var_dump($output);