Skip to content

Commit ca50db3

Browse files
author
roman_yakovenko
committed
replace popen with subprocess
1 parent 58dedeb commit ca50db3

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

pygccxml/parser/source_reader.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import linker
99
import config
1010
import patcher
11+
import subprocess
1112
import pygccxml.utils
1213

1314
try: #select the faster xml parser
@@ -148,16 +149,25 @@ def create_xml_file( self, header, destination=None ):
148149
if not os.path.isabs( ffname ):
149150
ffname = self.__file_full_name(header)
150151
command_line = self.__create_command_line( ffname, gccxml_file )
151-
input_, output = os.popen4( command_line )
152-
input_.close()
152+
153+
process = subprocess.Popen( args=command_line
154+
, shell=True
155+
, stdin=subprocess.PIPE
156+
, stdout=subprocess.PIPE
157+
, stderr=subprocess.STDOUT )
158+
process.stdin.close()
159+
153160
gccxml_reports = []
154-
while True:
155-
data = output.readline()
156-
gccxml_reports.append( data )
157-
if not data:
158-
break
159-
exit_status = output.close()
160-
gccxml_msg = ''.join(gccxml_reports)
161+
while process.poll() is None:
162+
line = process.stdout.readline()
163+
if line.strip():
164+
gccxml_reports.append( line.rstrip() )
165+
for line in process.stdout.readlines():
166+
if line.strip():
167+
gccxml_reports.append( line.rstrip() )
168+
169+
exit_status = process.returncode
170+
gccxml_msg = os.linesep.join(gccxml_reports)
161171
if self.__config.ignore_gccxml_output:
162172
if not os.path.isfile(gccxml_file):
163173
raise gccxml_runtime_error_t( "Error occured while running GCC-XML: %s status:%s" % (gccxml_msg, exit_status) )

0 commit comments

Comments
 (0)