@@ -148,22 +148,26 @@ def run_tesseract(input_filename,
148
148
lang ,
149
149
config = '' ,
150
150
nice = 0 ):
151
- command = []
151
+ cmd_args = []
152
152
153
153
if not sys .platform .startswith ('win32' ) and nice != 0 :
154
- command += ('nice' , '-n' , str (nice ))
154
+ cmd_args += ('nice' , '-n' , str (nice ))
155
155
156
- command += (tesseract_cmd , input_filename , output_filename_base )
156
+ cmd_args += (tesseract_cmd , input_filename , output_filename_base )
157
157
158
158
if lang is not None :
159
- command += ('-l' , lang )
159
+ cmd_args += ('-l' , lang )
160
160
161
- command += shlex .split (config )
161
+ cmd_args += shlex .split (config )
162
162
163
163
if extension != 'box' :
164
- command .append (extension )
164
+ cmd_args .append (extension )
165
+
166
+ try :
167
+ proc = subprocess .Popen (cmd_args , ** subprocess_args ())
168
+ except OSError :
169
+ raise TesseractNotFoundError ()
165
170
166
- proc = subprocess .Popen (command , ** subprocess_args ())
167
171
status_code , error_string = proc .wait (), proc .stderr .read ()
168
172
proc .stderr .close ()
169
173
@@ -177,7 +181,7 @@ def run_and_get_output(image,
177
181
extension ,
178
182
lang = None ,
179
183
config = '' ,
180
- nice = None ,
184
+ nice = 0 ,
181
185
return_bytes = False ):
182
186
183
187
temp_name , input_filename = '' , ''
@@ -191,15 +195,13 @@ def run_and_get_output(image,
191
195
'config' : config ,
192
196
'nice' : nice
193
197
}
194
- try :
195
- run_tesseract (** kwargs )
196
- filename = kwargs ['output_filename_base' ] + os .extsep + extension
197
- with open (filename , 'rb' ) as output_file :
198
- if return_bytes :
199
- return output_file .read ()
200
- return output_file .read ().decode ('utf-8' ).strip ()
201
- except OSError :
202
- raise TesseractNotFoundError ()
198
+
199
+ run_tesseract (** kwargs )
200
+ filename = kwargs ['output_filename_base' ] + os .extsep + extension
201
+ with open (filename , 'rb' ) as output_file :
202
+ if return_bytes :
203
+ return output_file .read ()
204
+ return output_file .read ().decode ('utf-8' ).strip ()
203
205
finally :
204
206
cleanup (temp_name )
205
207
0 commit comments