]> granicus.if.org Git - recode/commitdiff
common.py: use subprocess.check_output instead of os.popen
authorReuben Thomas <rrt@sc3d.org>
Mon, 29 Jan 2018 13:51:16 +0000 (13:51 +0000)
committerReuben Thomas <rrt@sc3d.org>
Mon, 29 Jan 2018 15:22:53 +0000 (15:22 +0000)
This is more long-winded, but os.popen doesn't seem to work with
Unix-style paths on Windows.

tests/common.py

index 2bb6bdf0ab8232d7930840db43df9dd73bb02a39..a759aa9b2cb30a548cfa323e101eb7f975c1f77b 100644 (file)
@@ -2,6 +2,7 @@
 
 __metaclass__ = type
 import os
+import subprocess
 from __main__ import py
 
 recode_program = os.environ.get('RECODE')
@@ -57,7 +58,12 @@ def external_output(command):
     if not recode_program:
         py.test.skip()
     command = command.replace('$R', recode_program + ' --ignore=:iconv:')
-    return os.popen(command, 'rb').read()
+    try:
+        # FIXME: Find a more portable solution than checking the OS
+        output = subprocess.check_output(command, universal_newlines=True, shell=os.name != 'nt')
+    except subprocess.CalledProcessError as e:
+        output = e.output
+    return output
 
 def recode_output(input):
     if run.external: