From 4cb31cc3edaa645d324260d5473046f28c644415 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 17 Mar 2022 17:16:25 +0100 Subject: [PATCH] fix async --- Ai/Ocr/Tesseract/TesseractOcr.php | 1 + System/SystemUtils.php | 16 ++++++++++++---- Utils/Parser/Pdf/PdfParser.php | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Ai/Ocr/Tesseract/TesseractOcr.php b/Ai/Ocr/Tesseract/TesseractOcr.php index 0b15e8cb1..cc82b044f 100644 --- a/Ai/Ocr/Tesseract/TesseractOcr.php +++ b/Ai/Ocr/Tesseract/TesseractOcr.php @@ -91,6 +91,7 @@ final class TesseractOcr self::$bin, $image . ' ' . ($temp = \tempnam(\sys_get_temp_dir(), 'ocr_')) + . ' -c preserve_interword_spaces=1' . ' --psm ' . $psm . ' --oem ' . $oem . ' -l ' . \implode('+', $languages) diff --git a/System/SystemUtils.php b/System/SystemUtils.php index 1a0398e86..d6f1cf09f 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -156,7 +156,7 @@ final class SystemUtils . $cmd; if ($async) { - $cmd .= ' > nul 2>&1'; + $cmd .= ' > nul 2>&1 &'; } } else { $cmd = \escapeshellarg($executable) @@ -164,7 +164,7 @@ final class SystemUtils . $cmd; if ($async) { - $cmd .= ' > /dev/null 2>&1'; + $cmd .= ' > /dev/null 2>&1 &'; } } @@ -180,8 +180,16 @@ final class SystemUtils throw new \Exception(); } - $stdout = \stream_get_contents($pipes[1]); - $stderr = \stream_get_contents($pipes[2]); + $stdout = ''; + $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) { \fclose($pipe); diff --git a/Utils/Parser/Pdf/PdfParser.php b/Utils/Parser/Pdf/PdfParser.php index accb758df..a73c5847b 100644 --- a/Utils/Parser/Pdf/PdfParser.php +++ b/Utils/Parser/Pdf/PdfParser.php @@ -81,7 +81,7 @@ class PdfParser SystemUtils::runProc( __DIR__ . '/../../../cOMS/Tools/InvoicePreprocessing/App', \escapeshellarg($file) . ' ' - . \escapeshellarg($file) + . \escapeshellarg($file) ); $ocr = new TesseractOcr();