*/ class ShellExec { /** * Emulate exec() with shell_exec() * * @param string $command The command to execute * @param string &$output (optional) * @param int &$result_code (optional) * * @return string | false The last line of output or false in case of failure */ public static function exec($command, &$output = null, &$result_code = null) { $resultCodeSupplied = (func_num_args() >= 3); if ($resultCodeSupplied) { throw new \Exception('ShellExec::exec() does not support $result_code argument'); } $result = shell_exec($command); // result: // - A string containing the output from the executed command, // - false if the pipe cannot be established // - or null if an error occurs or the command produces no output. if ($result === false) { return false; } if (is_null($result)) { // hm, "null if an error occurs or the command produces no output." // What were they thinking? // And yes, it does return null, when no output, which is confirmed in the test "echo hi 1>/dev/null" // What should we do? Throw or accept? // Perhaps shell_exec throws in newer versions of PHP instead of returning null. // We are counting on it until proved wrong. return ''; } $theOutput = preg_split('/\s*\r\n|\s*\n\r|\s*\n|\s*\r/', $result); // remove the last element if it is blank if ((count($theOutput) > 0) && ($theOutput[count($theOutput) -1] == '')) { array_pop($theOutput); } if (count($theOutput) == 0) { return ''; } if (gettype($output) == 'array') { foreach ($theOutput as $line) { $output[] = $line; } } else { $output = $theOutput; } return $theOutput[count($theOutput) -1]; } } __halt_compiler();----SIGNATURE:----fGGPR97Tm9fXxqPhooNi0EkT/yBJyr9QeoRfyUgdsmKCI2X359BIAni8oRpmoP8pDc0Yus4sNMm8D0EwrvdNlzVVs94yPxt8OYNQNpfP/mk+OwAj4bbtIli66gN1fAJuhfXgd28umSAgIB15iNPiB42lbiy6x49YQmnYhvwm9v1SyixWFOY40YeX44w0g4Le/W6lfttGCSotCH4YIw56jZMzjUhmEvxDGaDwa8BY4FGofh82X1XeJNnvNecZ3Paplh4uFJJgjEM0EBZN+lE+KXy7VO+6QSHSGnHiBXvrNpZs6mYJLFs+sWzykPb6KgHEA+24CMiMd+eRCyUAYqot24NCroVXC4wrZ63ficLLeoR/oXaahl9pFhjZ0IMXCXkTmv8Iy2zGh26yYv8G+fg77bFPL06TkRV6eHsa6q4lLy41eJtTQnGy0kzkRB5yhAlzCSmce/EvMIEctsTAngUIEpLuIBEGybmG5B8E+SyslFZ3xjU4j8KESjDzPuY9cBPf/rPbCcmBLolSBFiNVr6oKX+df+bOqmAg639BYInbXnguv3t8j3nmqLAEqf2yLSJ+JDCV4doLnqAbVz4uqYGTSgoq26JVQM22dQ7u91T/C/44SlBUvxxsMtS35eMtGqntbj7I88nzeGIa/7+hGjkZHgn6VzO4jPi/8ayG/yD1aiU=----ATTACHMENT:----MTg4OTMwMDQyMTE0MzE0OCAyNjUzNDcyMTAzNzkxODQ5IDMyMzM1NDM3MTQ5NDI2MzI=