*/ 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:----vh/05TGv2ddYhj7NpgJxfdDQR3PVOBiefDY/o+Lng2EIwS/rVc7xqgQZDIYrPtoWVpHzWADqLju1xQOf3Akah8VBhCBIHKWVoNY7IJb1FpojoAjWYyhsI0qSQ9eA8ymz8i7zFxuDumJ5rnzuQhZjGPCllTbLtYVfJHWgAbXN3KZw2PlYUlrgLTcbJehf+O0VgLzg8WeAEwMvnqFBfpv31JzmXiyJ9P4A+1IPEcQO9eJaioQljWt7DqmIReI6WOpR4BRLAKu3o1D75F3TedZ06Q0knDaO09kOetogKBEZS3dIvTF2ZAq8QO41rrtHqzMv7jxPaEoc74wY3VusSujqJQZfustljN5fO5SWiezeKht3mGeahOIjzKw8Di0kVV01IU4oR3CeIOK8ft7ctbd4gq5PKbUM8WfObgZzEPIheCvTJBhWb+311GgJHoofo9ig2DuS2rEla5ekKXmCfCP6hNNp5mZNUC2esm1Uf5S62bme02Mi6I1ut+1vj1DUbrwBDJnFkEcpsMgFdAzxgGU9cPR1n89dW+D66o24WPQbkoeqWt7IpanIAi0XNhoONWaNQDgDsAakJBUoEkdr1sWcXP0tBJyflWRzNYqz91Wst16wlDkW0zOeyaxfeG9rV+jxLzLGPSvsxo8AnIr3OsH3JdkGELMqKOk70Wf+Phk8s8A=----ATTACHMENT:----NDM4MTAyNDkzMDY0NTEwMyA5MTcwMDg2NDYyODY3NTQ0IDE3Njg0MTQ4OTk3NjA3MzU=