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

create new console with no new window if in win32 #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ tests/gif/standardized_text.txt
tests/jpg/standardized_text.txt
tests/tiff/standardized_text.txt
tests/pdf/ocr_text.txt

.idea
12 changes: 11 additions & 1 deletion textract/parsers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import subprocess
import sys
import tempfile
import os
import errno
Expand All @@ -12,6 +13,8 @@

from .. import exceptions

IS_WIN32 = 'win32' in str(sys.platform).lower()


class BaseParser(object):
"""The :class:`.BaseParser` abstracts out some common functionality
Expand Down Expand Up @@ -76,12 +79,19 @@ def run(self, args):
as a tuple. If the command is not successful, this raises a
:exc:`textract.exceptions.ShellError`.
"""

# create new console with no new window if in win32
if IS_WIN32:
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
else:
startupinfo = None
# run a subprocess and put the stdout and stderr on the pipe object
try:
pipe = subprocess.Popen(
args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
startupinfo=startupinfo
)
except OSError as e:
if e.errno == errno.ENOENT:
Expand Down