From 359e16a7b223803d4c45d04e13b802fe0f0e71fa Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Wed, 6 Sep 2023 17:49:57 -0700 Subject: [PATCH] CommandLineRunner is extremely sensitive to argument order It will fail in strange ways unless the file URIs *precede* all of the other arguments, including --raw. --- zxing/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zxing/__init__.py b/zxing/__init__.py index 5cb5af5..406ee08 100644 --- a/zxing/__init__.py +++ b/zxing/__init__.py @@ -85,7 +85,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod fn = fn_or_im file_uris.append(pathlib.Path(fn).absolute().as_uri()) - cmd = [self.java, '-cp', self.classpath, self.cls] + cmd = [self.java, '-cp', self.classpath, self.cls] + file_uris if self.zxing_version_info and self.zxing_version_info >= (3, 5, 0): cmd.append('--raw') if try_harder: @@ -97,7 +97,6 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod if possible_formats: for pf in possible_formats: cmd += ['--possible_formats', pf] - cmd += file_uris try: p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.STDOUT, universal_newlines=False) @@ -129,7 +128,7 @@ def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcod fn = file_uri_to_path(stdout.splitlines()[0][63:].decode()) raise BarCodeReaderException("Java library could not read image (is it in a supported format?)", fn) elif stdout.startswith(b'''Exception '''): - raise BarCodeReaderException("Unknown Java exception", self.java) from RuntimeError(stdout) + raise BarCodeReaderException("Unknown Java exception", self.java) from sp.CalledProcessError(0, cmd, stdout) elif p.returncode: raise BarCodeReaderException("Unexpected Java subprocess return code", self.java) from sp.CalledProcessError(p.returncode, cmd, stdout)