/**
  * Function that attempts to return the correct executable path.
  * @return string WKHTMLTOPDF path.
  */
 protected static function _getCMD()
 {
     if (self::$_cmd == '') {
         // the end filename is in the form of "(%PATH%)wkhtmltopdf[-(win|osx|lin)-(amd64|i386|ppc)][.exe]"
         self::$_cmd = $GLOBALS['WKPDF_BASE_PATH'];
         self::$_cmd .= self::_getOS() == 'win' ? 'wkhtmltopdf.exe' : 'wkhtmltopdf-' . self::_getOS() . '-' . self::_getCPU();
     }
     switch (self::_getOS()) {
         case 'win':
             // checks file existence (permissions on windows isn't much of a problem)
             // for windows, the command is "exists %filename%" ... try it out?
             break;
         case 'lin':
         case 'osx':
             // checks file existence and permissions using LS
             $exists = self::_pipeExec('test -f "' . self::$_cmd . '"');
             if ($exists['return'] > 0) {
                 throw new Exception('WKPDF executable couldn\'t be found ("' . htmlspecialchars(self::$_cmd) . '").');
             }
             $exists = explode(' ', str_replace('  ', ' ', str_replace('	', ' ', $exists['stdout'])));
             // perms, unused, group, user, ...
             if (count($exists) > 1) {
                 // "test" command ran, keep testing settings, otherwise just ignore tests...
                 if (strstr($exists[0], 'rwxrwxrwx') === false) {
                     if ($exists[2] != get_current_user() || $exists[3] != get_current_user()) {
                         throw new Exception('WKPDF executable permissions are not 0777 or user/group does not match with current user/group.');
                     }
                 }
             }
             break;
     }
     return self::$_cmd;
 }