locally executed commands need to set universal_newlines too in py3
[nepi.git] / nepi / util / execfuncs.py
index a78ef39..a8591f8 100644 (file)
@@ -22,6 +22,8 @@ import logging
 import shlex
 import subprocess
 
+from six import PY2
+
 def lexec(command, 
         user = None, 
         sudo = False,
@@ -42,10 +44,12 @@ def lexec(command,
     #elif user:
     #    command = "su %s ; %s " % (user, command)
 
+    extras = {} if PY2 else {'universal_newlines' : True}
     proc = subprocess.Popen(command,
-                shell = True, 
-                stdout = subprocess.PIPE, 
-                stderr = subprocess.PIPE)
+                            shell = True, 
+                            stdout = subprocess.PIPE, 
+                            stderr = subprocess.PIPE,
+                            **extras)
 
     out = err = ""
     log_msg = "lexec - command %s " % command
@@ -78,9 +82,11 @@ def lcopy(source, dest, recursive = False):
     else:
         args.append(dest)
 
+    extras = {} if PY2 else {'universal_newlines' : True}
     proc = subprocess.Popen(args, 
-        stdout=subprocess.PIPE, 
-        stderr=subprocess.PIPE)
+                            stdout=subprocess.PIPE, 
+                            stderr=subprocess.PIPE,
+                            **extras)
 
     out = err = ""
     command = " ".join(args)