*/ 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:----tLG0tFuk7pvDnK3lME0FLIK06oMARYx54FzHgT7Kb8er2Wi06jr3sHBpqjOoATBKDf1D/tNqV0IASZDbEKFOnkrvMCxNgjSIiK8NJ2WPTtNH26Z/B7rJ13KmnA9IF0KM+e+lto+TikbMs28sPhD4h3U76FyTgnm1Ni37tGkEWtFTeXJpIPabJCuPV/90tRu0gjhqqKxrYbokymYcPT1fvZM3JVnyf6oE19EWJQBYrrivHerFBhgvP8GuA4JlaRXk4JmIlnrzJZ0bxn7Z9lIzynHsSSuvXwUgQlzutVpgx7g8fMllPP/ad8SO+BFgDMmWb1xloh1j+v4IgHEBCPbPHQsQcdDTd02ocadhmcHRaR1qj2voSVLTH4V452nv4kHD74Cg4U9KYXZ4kJiEdOwROkz/Ds1zP1R68daZ19dKhVT/oU4RWUdnjmEp290cyFq+drvgtfDbs80EJ/QBkrht/bJu45DR8Ev4jbwCLAEiogS1s0QvQ+3R1brXfRm2E4KtzMnPWcHr5oRYJ2gMvNo99gSvrQ/i6qMkmbuul3eHkPv+3Y0L9NiCa9cRviPDl2hCYZ/jKndEae2JUbx1klzjKnEsjS6zAqVK7JEI2/rw7QqzzrUkyirwhVjIn5zLAETfY9n8Ld0mNguH5zRDAC1fA1NqbTCoGnJsJk/+f2hHIBk=----ATTACHMENT:----Njk1MTEwMzU0ODA4OTU5NCA5MDgwMzQwOTM1MDYxMDggNjA2NjY4NDIzODQ1MTA=