Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to hide console window #41

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/pytesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@

__all__ = ['image_to_string']

def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False, config=None):
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW


def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False, config=None, hide_window=False):
'''
runs the command:
`tesseract_cmd` `input_filename` `output_filename_base`
Expand All @@ -90,8 +94,11 @@ def run_tesseract(input_filename, output_filename_base, lang=None, boxes=False,
if config:
command += shlex.split(config)

proc = subprocess.Popen(command,
stderr=subprocess.PIPE)
kw = dict(stderr=subprocess.PIPE)
if hide_window:
kw.update(startupinfo=si)

proc = subprocess.Popen(command, **kw)
return (proc.wait(), proc.stderr.read())

def cleanup(filename):
Expand Down Expand Up @@ -125,7 +132,7 @@ def __init__(self, status, message):
self.message = message
self.args = (status, message)

def image_to_string(image, lang=None, boxes=False, config=None):
def image_to_string(image, lang=None, boxes=False, config=None, hide_window=False):
'''
Runs tesseract on the specified image. First, the image is written to disk,
and then the tesseract command is run on the image. Resseract's result is
Expand Down Expand Up @@ -158,7 +165,8 @@ def image_to_string(image, lang=None, boxes=False, config=None):
output_file_name_base,
lang=lang,
boxes=boxes,
config=config)
config=config,
hide_window=hide_window)
if status:
errors = get_errors(error_string)
raise TesseractError(status, errors)
Expand Down