Use subprocess instead of os.popen4 to fix deprecation warning. Closes #89394

authorJulien Cristau <julien.cristau@logilab.fr>
changesetd6266544b25c
branchdefault
phasepublic
hiddenno
parent revision#5a232029d333 fix url and update copyright
child revision#57ab0d40a1bc [packaging] add spec file, #c8ac22ffdb7d default is stable
files modified by this revision
transforms/cmdtransforms.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1331816298 -3600
# Thu Mar 15 13:58:18 2012 +0100
# Node ID d6266544b25c7469958a4acf5c99ec32e9037ae1
# Parent 5a232029d333959363653a9500ba19985ca45872
Use subprocess instead of os.popen4 to fix deprecation warning. Closes #89394

diff --git a/transforms/cmdtransforms.py b/transforms/cmdtransforms.py
@@ -15,10 +15,11 @@
1  #
2  # You should have received a copy of the GNU Lesser General Public License along
3  # with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>.
4  import os
5  from tempfile import mkstemp
6 +import subprocess
7 
8  from logilab.mtconverter import MissingBinary
9  from logilab.mtconverter.transform import Transform
10 
11  bin_search_path = [path for path in os.environ['PATH'].split(os.pathsep)
@@ -75,11 +76,13 @@
12          if not self.use_stdin:
13              tmpfile, tmpname = mkstemp(text=False) # create tmp
14              os.write(tmpfile, data) # write data to tmp using a file descriptor
15              os.close(tmpfile)       # close it so the other process can read it
16              command = command % {'infile' : tmpname} # apply tmp name to command
17 -        cin, couterr = os.popen4(command, 'b')
18 +        cin, couterr = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE,
19 +                                        stdout=subprocess.PIPE,
20 +                                        stderr=subprocess.STDOUT, close_fds=True)
21          if self.use_stdin:
22              cin.write(data)
23          status = cin.close()
24          out = couterr.read()
25          couterr.close()