Skip to content

Commit e8502f0

Browse files
hide subprocess consoles on Windows (#656)
1 parent 169a41e commit e8502f0

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

kindlecomicconverter/KCC_gui.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from distutils.version import StrictVersion
3535
from raven import Client
3636
from tempfile import gettempdir
37-
from .shared import md5Checksum, HTMLStripper, sanitizeTrace, walkLevel
37+
from .shared import md5Checksum, HTMLStripper, sanitizeTrace, walkLevel, subprocess_run_silent
3838
from . import __version__
3939
from . import comic2ebook
4040
from . import metadata
@@ -837,7 +837,7 @@ def detectKindleGen(self, startup=False):
837837
except Exception:
838838
pass
839839
try:
840-
versionCheck = subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
840+
versionCheck = subprocess_run_silent(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
841841
self.kindleGen = True
842842
for line in versionCheck.stdout.splitlines():
843843
if 'Amazon kindlegen' in line:
@@ -1026,7 +1026,7 @@ def __init__(self, kccapp, kccwindow):
10261026
'<a href="https://github.com/ciromattia/kcc/wiki/Important-tips">important tips</a>.',
10271027
'info')
10281028
try:
1029-
subprocess.run(['7z'], stdout=PIPE, stderr=STDOUT)
1029+
subprocess_run_silent(['7z'], stdout=PIPE, stderr=STDOUT)
10301030
self.sevenzip = True
10311031
except FileNotFoundError:
10321032
self.sevenzip = False

kindlecomicconverter/comic2ebook.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from PyQt5 import QtCore
4545
except ImportError:
4646
QtCore = None
47-
from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, sanitizeTrace
47+
from .shared import md5Checksum, getImageFileName, walkSort, walkLevel, sanitizeTrace, subprocess_run_silent
4848
from . import comic2panel
4949
from . import image
5050
from . import comicarchive
@@ -1104,13 +1104,13 @@ def checkTools(source):
11041104
if source.endswith('.CB7') or source.endswith('.7Z') or source.endswith('.RAR') or source.endswith('.CBR') or \
11051105
source.endswith('.ZIP') or source.endswith('.CBZ'):
11061106
try:
1107-
subprocess.run(['7z'], stdout=PIPE, stderr=STDOUT)
1107+
subprocess_run_silent(['7z'], stdout=PIPE, stderr=STDOUT)
11081108
except FileNotFoundError:
11091109
print('ERROR: 7z is missing!')
11101110
sys.exit(1)
11111111
if options.format == 'MOBI':
11121112
try:
1113-
subprocess.run(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT)
1113+
subprocess_run_silent(['kindlegen', '-locale', 'en'], stdout=PIPE, stderr=STDOUT)
11141114
except FileNotFoundError:
11151115
print('ERROR: KindleGen is missing!')
11161116
sys.exit(1)
@@ -1267,7 +1267,7 @@ def makeMOBIWorker(item):
12671267
kindlegenError = ''
12681268
try:
12691269
if os.path.getsize(item) < 629145600:
1270-
output = subprocess.run(['kindlegen', '-dont_append_source', '-locale', 'en', item],
1270+
output = subprocess_run_silent(['kindlegen', '-dont_append_source', '-locale', 'en', item],
12711271
stdout=PIPE, stderr=STDOUT, encoding='UTF-8')
12721272
for line in output.stdout.splitlines():
12731273
# ERROR: Generic error

kindlecomicconverter/comicarchive.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from subprocess import STDOUT, PIPE
2727
from xml.dom.minidom import parseString
2828
from xml.parsers.expat import ExpatError
29+
from .shared import subprocess_run_silent
2930

3031
EXTRACTION_ERROR = 'Failed to extract archive. Try extracting file outside of KCC.'
3132

@@ -36,13 +37,13 @@ def __init__(self, filepath):
3637
self.type = None
3738
if not os.path.isfile(self.filepath):
3839
raise OSError('File not found.')
39-
process = subprocess.run(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
40+
process = subprocess_run_silent(['7z', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
4041
for line in process.stdout.splitlines():
4142
if b'Type =' in line:
4243
self.type = line.rstrip().decode().split(' = ')[1].upper()
4344
break
4445
if process.returncode != 0 and distro.id() == 'fedora':
45-
process = subprocess.run(['unrar', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
46+
process = subprocess_run_silent(['unrar', 'l', '-y', '-p1', self.filepath], stderr=STDOUT, stdout=PIPE)
4647
for line in process.stdout.splitlines():
4748
if b'Details: ' in line:
4849
self.type = line.rstrip().decode().split(' ')[1].upper()
@@ -53,15 +54,15 @@ def __init__(self, filepath):
5354
def extract(self, targetdir):
5455
if not os.path.isdir(targetdir):
5556
raise OSError('Target directory doesn\'t exist.')
56-
process = subprocess.run(['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath],
57+
process = subprocess_run_silent(['7z', 'x', '-y', '-xr!__MACOSX', '-xr!.DS_Store', '-xr!thumbs.db', '-xr!Thumbs.db', '-o' + targetdir, self.filepath],
5758
stdout=PIPE, stderr=STDOUT)
5859
if process.returncode != 0 and distro.id() == 'fedora':
59-
process = subprocess.run(['unrar', 'x', '-y', '-x__MACOSX', '-x.DS_Store', '-xthumbs.db', '-xThumbs.db', self.filepath, targetdir]
60+
process = subprocess_run_silent(['unrar', 'x', '-y', '-x__MACOSX', '-x.DS_Store', '-xthumbs.db', '-xThumbs.db', self.filepath, targetdir]
6061
, stdout=PIPE, stderr=STDOUT)
6162
if process.returncode != 0:
6263
raise OSError(EXTRACTION_ERROR)
6364
elif process.returncode != 0 and platform.system() == 'Darwin':
64-
process = subprocess.run(['unar', self.filepath, '-f', '-o', targetdir],
65+
process = subprocess_run_silent(['unar', self.filepath, '-f', '-o', targetdir],
6566
stdout=PIPE, stderr=STDOUT)
6667
elif process.returncode != 0:
6768
raise OSError(EXTRACTION_ERROR)
@@ -73,13 +74,13 @@ def extract(self, targetdir):
7374
def addFile(self, sourcefile):
7475
if self.type in ['RAR', 'RAR5']:
7576
raise NotImplementedError
76-
process = subprocess.run(['7z', 'a', '-y', self.filepath, sourcefile],
77+
process = subprocess_run_silent(['7z', 'a', '-y', self.filepath, sourcefile],
7778
stdout=PIPE, stderr=STDOUT)
7879
if process.returncode != 0:
7980
raise OSError('Failed to add the file.')
8081

8182
def extractMetadata(self):
82-
process = subprocess.run(['7z', 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'],
83+
process = subprocess_run_silent(['7z', 'x', '-y', '-so', self.filepath, 'ComicInfo.xml'],
8384
stdout=PIPE, stderr=STDOUT)
8485
if process.returncode != 0:
8586
raise OSError(EXTRACTION_ERROR)

kindlecomicconverter/shared.py

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
from hashlib import md5
2323
from html.parser import HTMLParser
24+
import subprocess
2425
from distutils.version import StrictVersion
2526
from re import split
2627
import sys
@@ -135,3 +136,8 @@ def dependencyCheck(level):
135136
if len(missing) > 0:
136137
print('ERROR: ' + ', '.join(missing) + ' is not installed!')
137138
sys.exit(1)
139+
140+
def subprocess_run_silent(command, **kwargs):
141+
if (os.name == 'nt'):
142+
kwargs.setdefault('creationflags', subprocess.CREATE_NO_WINDOW)
143+
return subprocess.run(command, **kwargs)

0 commit comments

Comments
 (0)