diff --git a/lib/util/ktutil.inc b/lib/util/ktutil.inc index d454476..85608e5 100644 --- a/lib/util/ktutil.inc +++ b/lib/util/ktutil.inc @@ -206,27 +206,56 @@ class KTUtil { $aOutput = array(); $iRet = ''; - if (OS_WINDOWS){ - $wait = false; - if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'true')){ - $wait = true; - } - - $WshShell = new COM("WScript.Shell"); - $res = $WshShell->Run($sCmd, 0, $wait); - - $iRet = 0; - $aOutput = array($res); - }else{ - exec($sCmd, $aOutput, $iRet); - } - + exec($sCmd, $aOutput, $iRet); $aRet['ret'] = $iRet; $aRet['out'] = $aOutput; return $aRet; } // }}} + + // {{{ winexec + /** + * Execute a command on a windows platform. + */ + function winexec($aCmd, $aOptions = null) { + if (is_array($aCmd)) { + $sCmd = KTUtil::safeShellString($aCmd); + } else { + $sCmd = $aCmd; + } + $sAppend = KTUtil::arrayGet($aOptions, 'append'); + if ($sAppend) { + $sCmd .= " >> " . escapeshellarg($sAppend); + } + + $sCmd = str_replace( '/','\\',$sCmd); + + // Set wait to true if the execute must wait for the script to complete before continuing + $wait = true; + if(isset($aOptions['exec_wait']) && ($aOptions['exec_wait'] == 'false')){ + $wait = false; + } + + // Iterate through the various execute functions till one works. + $WshShell = new COM("WScript.Shell"); + $res = $WshShell->Run($sCmd, 0, $wait); + + if($res){ + return $res; + } + + $sCmd = "start /b \"kt\" " . $sCmd; + $fp = popen($sCmd, 'r'); + fclose($fp); + + if($wait){ + sleep(1); + } + return 1; + } + // }}} + // {{{ copyDirectory function copyDirectory($sSrc, $sDst, $bMove = false) { if (file_exists($sDst)) { @@ -500,6 +529,12 @@ class KTUtil { return $sCommand . ".exe"; } + $result = KTUtil::checkForStackCommand($sConfigVar); + if (!empty($result)) + { + return $result; + } + $sExecSearchPath = $oKTConfig->get("KnowledgeTree/execSearchPath"); $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../common/"; $sExecSearchPath .= PATH_SEPARATOR . KT_DIR . "/../bin/xpdf/"; @@ -521,6 +556,47 @@ class KTUtil { } // }}} + function checkForStackCommand($configCommand) + { + $config = KTConfig::getSingleton(); + $stackPath = realpath(KT_DIR . '/..'); + + switch ($configCommand) + { + case 'externalBinary/php': + if (OS_WINDOWS) + { + $script = $stackPath . '/php/php.exe'; + } + else + { + $script = $stackPath . '/php/bin/php'; + } + break; + case 'externalBinary/python': + if (OS_WINDOWS) + { + $script = $stackPath . '/openoffice/openoffice/program/python.bat'; + } + else + { + $script = $stackPath . '/openoffice/program/python'; + } + break; + case 'externalBinary/java': + $script = $stackPath . '/j2re/bin/java'; + break; + default: + return null; + } + if (is_file($script)) + { + return $script; + } + return false; + } + + // now accepts strings OR arrays! // {{{ addQueryString function addQueryString($url, $qs) { diff --git a/plugins/ktstandard/contents/BaseIndexer.php b/plugins/ktstandard/contents/BaseIndexer.php index 28640f3..764d387 100644 --- a/plugins/ktstandard/contents/BaseIndexer.php +++ b/plugins/ktstandard/contents/BaseIndexer.php @@ -147,7 +147,12 @@ class KTBaseIndexerTrigger { } else { $cmdline[] = $sTempFilename; } - $aRet = KTUtil::pexec($cmdline, $aOptions); + + if(OS_WINDOWS){ + $aRet = KTUtil::winexec($cmdline, $aOptions); + }else{ + $aRet = KTUtil::pexec($cmdline, $aOptions); + } $this->aCommandOutput = $aRet['out']; $contents = file_get_contents($sTempFilename); diff --git a/plugins/ktstandard/contents/WordIndexer.php b/plugins/ktstandard/contents/WordIndexer.php index 7c1a8d7..7d6343b 100644 --- a/plugins/ktstandard/contents/WordIndexer.php +++ b/plugins/ktstandard/contents/WordIndexer.php @@ -57,6 +57,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { $sDir = dirname(dirname($sCommand)); putenv('HOME=' . $sDir); + /* $cmdline = array($sCommand); $cmdline = kt_array_merge($cmdline, $this->args); $cmdline[] = $sFilename; @@ -73,6 +74,7 @@ class KTWordIndexerTrigger extends KTBaseIndexerTrigger { $this->aCommandOutput = 1; $contents = file_get_contents($sTempFilename); return $contents; + */ } return parent::extract_contents($sFilename, $sTempFilename); }