fix async

This commit is contained in:
Dennis Eichhorn 2022-03-17 17:16:25 +01:00
parent a03fd72dbd
commit 4cb31cc3ed
3 changed files with 14 additions and 5 deletions

View File

@ -91,6 +91,7 @@ final class TesseractOcr
self::$bin, self::$bin,
$image . ' ' $image . ' '
. ($temp = \tempnam(\sys_get_temp_dir(), 'ocr_')) . ($temp = \tempnam(\sys_get_temp_dir(), 'ocr_'))
. ' -c preserve_interword_spaces=1'
. ' --psm ' . $psm . ' --psm ' . $psm
. ' --oem ' . $oem . ' --oem ' . $oem
. ' -l ' . \implode('+', $languages) . ' -l ' . \implode('+', $languages)

View File

@ -156,7 +156,7 @@ final class SystemUtils
. $cmd; . $cmd;
if ($async) { if ($async) {
$cmd .= ' > nul 2>&1'; $cmd .= ' > nul 2>&1 &';
} }
} else { } else {
$cmd = \escapeshellarg($executable) $cmd = \escapeshellarg($executable)
@ -164,7 +164,7 @@ final class SystemUtils
. $cmd; . $cmd;
if ($async) { if ($async) {
$cmd .= ' > /dev/null 2>&1'; $cmd .= ' > /dev/null 2>&1 &';
} }
} }
@ -180,8 +180,16 @@ final class SystemUtils
throw new \Exception(); throw new \Exception();
} }
$stdout = \stream_get_contents($pipes[1]); $stdout = '';
$stderr = \stream_get_contents($pipes[2]); $stderr = '';
if ($async) {
\stream_set_blocking($pipes[1], false);
\stream_set_blocking($pipes[2], false);
} else {
$stdout = \stream_get_contents($pipes[1]);
$stderr = \stream_get_contents($pipes[2]);
}
foreach ($pipes as $pipe) { foreach ($pipes as $pipe) {
\fclose($pipe); \fclose($pipe);

View File

@ -81,7 +81,7 @@ class PdfParser
SystemUtils::runProc( SystemUtils::runProc(
__DIR__ . '/../../../cOMS/Tools/InvoicePreprocessing/App', __DIR__ . '/../../../cOMS/Tools/InvoicePreprocessing/App',
\escapeshellarg($file) . ' ' \escapeshellarg($file) . ' '
. \escapeshellarg($file) . \escapeshellarg($file)
); );
$ocr = new TesseractOcr(); $ocr = new TesseractOcr();