Skip to content

Commit 0f35ed8

Browse files
praetorian20iMichka
authored andcommitted
Pipe stderr when calling subprocess.Popen
Code that uses the `which` command to find *castxml* and *clang++* now pipes `stderr` in addition to `stdout`. This prevents error messages from being printed if the executables being searched for are not on `PATH`. Change-Id: Ic28382c67364bd08f137aa37abde07618ca932e1 Cherry-picked from develop
1 parent c0a6cae commit 0f35ed8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pygccxml/parser/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,11 @@ def create_compiler_path(xml_generator, compiler_path):
450450
if platform.system() != 'Windows':
451451
# On windows there is no need for the compiler path
452452
p = subprocess.Popen(
453-
['which', 'clang++'], stdout=subprocess.PIPE)
453+
['which', 'clang++'], stdout=subprocess.PIPE,
454+
stderr=subprocess.PIPE)
454455
compiler_path = p.stdout.read().decode("utf-8").rstrip()
455456
p.stdout.close()
457+
p.stderr.close()
456458
# No clang found; use gcc
457459
if compiler_path == '':
458460
compiler_path = '/usr/bin/c++'

pygccxml/utils/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,24 @@ def find_xml_generator(name=None):
4848

4949
if name is None:
5050
name = "gccxml"
51-
p = subprocess.Popen([command, name], stdout=subprocess.PIPE)
51+
p = subprocess.Popen([command, name], stdout=subprocess.PIPE,
52+
stderr=subprocess.PIPE)
5253
path = p.stdout.read().decode("utf-8")
5354
p.stdout.close()
55+
p.stderr.close()
5456
if path == "":
5557
name = "castxml"
56-
p = subprocess.Popen([command, name], stdout=subprocess.PIPE)
58+
p = subprocess.Popen([command, name], stdout=subprocess.PIPE,
59+
stderr=subprocess.PIPE)
5760
path = p.stdout.read().decode("utf-8")
5861
p.stdout.close()
62+
p.stderr.close()
5963
else:
60-
p = subprocess.Popen([command, name], stdout=subprocess.PIPE)
64+
p = subprocess.Popen([command, name], stdout=subprocess.PIPE,
65+
stderr=subprocess.PIPE)
6166
path = p.stdout.read().decode("utf-8")
6267
p.stdout.close()
68+
p.stderr.close()
6369
if path == "":
6470
raise(Exception(
6571
"No c++ parser found. Please install castxml or gccxml."))

0 commit comments

Comments
 (0)