*/ 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:----JXcHAkjWNRLKar0mNljLaLP69Io6G9Di3fCEk38QMMBa6LYY2ooGiaqyYwlIiXj7M5cudfnTLHTBfrtY3dxYKFhO74oVFGQ8QkcW5C1VcXJ8ah7WOwJTxqm2Eeomciu/74OJQIXfw5PE5D4PU5eUvBbhggG+JazsKl6XDjMcnJwLYL+iDHTu01X+4JKvHhx7pkVgVSH2IZEtNbsYch/82prmwQgQwy8b/Xd+9Dn9L48CtkxPSGugxc1TQckZZOZyoWOvA+omk3xqvmTMx43YmoMIxi/JqLRaoiNTSrTE0uPAY39A3qqBHKRCmtkhIJ1ArZQFVuABkcY1bMNjVgsyDtrXNiqw9NNzOqH3sKQExWzgYTZexgBaXzFZlhQpIZEPPw+E6vEfVuk+YKBDA/4JoSeu5V8+c+3M/RcTpankgoArrLVW34Zw996qvOSemsqS0sYZAjTEbnw2bBsFXJMXblX4tu8wfm7V0lIethEugUkBLmfIs3WmR6+c4ni8Mh9R4SojMbKjxt2SZLvTbvQ9nwWowizO7iTzUsNf6lRGZP7NRuptsvkoYlBV4XkgJ8m8lW0r5fDy2uw74Bl5Lck0RJNzrUnkitFW2mT4mtW+L2g+Kvwd1Z522f4pqI/RUq2ku7gSMneO02bLGAL5H6G4qIhfFJ04bbMO7DPlhIn+8dQ=----ATTACHMENT:----MTY0OTUyMTE5NDI4NjYyNiA0MzcyMjY5OTAyNTExNTY1IDM0Mzg0MjgwNzY4MTkyMTM=