Commit 57688b6072babf130a022f2927346c9d20f78433
1 parent
fe110665
KTS-2903
"Improved capture of output from exec on text extractors" Fixed Committed By: Conrad Vermeulen Reviewed By: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8000 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
57 additions
and
5 deletions
search2/indexing/extractorCore.inc.php
| @@ -101,6 +101,13 @@ abstract class DocumentExtractor | @@ -101,6 +101,13 @@ abstract class DocumentExtractor | ||
| 101 | */ | 101 | */ |
| 102 | protected $indexStatus; | 102 | protected $indexStatus; |
| 103 | 103 | ||
| 104 | + /** | ||
| 105 | + * If an error occurred, this is the output that was captured | ||
| 106 | + * | ||
| 107 | + * @var string | ||
| 108 | + */ | ||
| 109 | + public $output; | ||
| 110 | + | ||
| 104 | 111 | ||
| 105 | public function __construct() | 112 | public function __construct() |
| 106 | { | 113 | { |
| @@ -349,21 +356,66 @@ abstract class ExternalDocumentExtractor extends DocumentExtractor | @@ -349,21 +356,66 @@ abstract class ExternalDocumentExtractor extends DocumentExtractor | ||
| 349 | */ | 356 | */ |
| 350 | protected function exec($cmd) | 357 | protected function exec($cmd) |
| 351 | { | 358 | { |
| 359 | + $config = KTConfig::getSingleton(); | ||
| 360 | + $temp_dir = $config->get('urls/tmpDirectory'); | ||
| 361 | + $res = 0; | ||
| 362 | + | ||
| 363 | + $script_prefix = $temp_dir . '/' . time(); | ||
| 364 | + $script_out = $script_prefix . '.out'; | ||
| 365 | + | ||
| 366 | + // define the scripts that we want | ||
| 367 | + | ||
| 352 | if (OS_WINDOWS) | 368 | if (OS_WINDOWS) |
| 353 | { | 369 | { |
| 370 | + $script_name = $script_prefix . '.bat'; | ||
| 354 | 371 | ||
| 372 | + $script = "rem This is an auto generated file. \n"; | ||
| 373 | + $script .= $cmd . ' 2> ' . $script_out . "\r\n"; | ||
| 374 | + } | ||
| 375 | + else | ||
| 376 | + { | ||
| 377 | + $script_name = $script_prefix . '.sh'; | ||
| 355 | 378 | ||
| 356 | - $WshShell = new COM("WScript.Shell"); | ||
| 357 | - $res = $WshShell->Run($cmd, 0, true); | 379 | + $script = "#!/bin/sh\n"; |
| 380 | + $script .= "# This is an auto generated file. \n"; | ||
| 381 | + $script .= $cmd . ' 2> ' . $script_out . "\n"; | ||
| 382 | + $script .= "exit $?\n"; | ||
| 383 | + } | ||
| 358 | 384 | ||
| 385 | + // write the script file | ||
| 386 | + if (file_put_contents($script_name, $script) === false) | ||
| 387 | + { | ||
| 388 | + $this->output = _kt('Could not create exec script: ') . $script_name; | ||
| 389 | + return false; | ||
| 390 | + } | ||
| 359 | 391 | ||
| 360 | - return $res == 0; | 392 | + // execute the script file |
| 393 | + if (OS_WINDOWS) | ||
| 394 | + { | ||
| 395 | + $WshShell = new COM("WScript.Shell"); | ||
| 396 | + $res = $WshShell->Run($script_name, 0, true); | ||
| 361 | } | 397 | } |
| 362 | else | 398 | else |
| 363 | { | 399 | { |
| 364 | - $aRet = KTUtil::pexec($cmd); | ||
| 365 | - return $aRet['ret'] == 0; | 400 | + if (chmod($script_name, 0755) === false) |
| 401 | + { | ||
| 402 | + $this->output = _kt('Could change permission on exec script: ') . $script_name; | ||
| 403 | + return false; | ||
| 404 | + } | ||
| 405 | + $aRet = KTUtil::pexec($script_name); | ||
| 406 | + $res = $aRet['ret']; | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + // remote the script file and get the output if available | ||
| 410 | + @unlink($script_name); | ||
| 411 | + | ||
| 412 | + if (file_exists($script_out)) | ||
| 413 | + { | ||
| 414 | + $this->output = file_get_contents($script_out); | ||
| 415 | + @unlink($script_out); | ||
| 366 | } | 416 | } |
| 417 | + | ||
| 418 | + return $res == 0; | ||
| 367 | } | 419 | } |
| 368 | 420 | ||
| 369 | /** | 421 | /** |