From 5614ce16d79318427b712e418466209d694a9d03 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Sun, 27 May 2018 17:47:47 +0100
Subject: [PATCH] RF: Improve test for bytes-vs-str output streams

---
 fsl/utils/run.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fsl/utils/run.py b/fsl/utils/run.py
index 9e916d810..7ea69adf2 100644
--- a/fsl/utils/run.py
+++ b/fsl/utils/run.py
@@ -127,11 +127,16 @@ def run(*args, **kwargs):
     # the process stdout/err on separate threads
     # to avoid deadlocks.
     def forward(in_, *outs):
+
+        # not all file-likes have a mode attribute -
+        # if not present, assume a string stream
+        omodes = [getattr(o, 'mode', 'w') for o in outs]
+
         def realForward():
             for line in in_:
-                for o in outs:
-                    if 'b' in o.mode: o.write(line)
-                    else:             o.write(line.decode('utf-8'))
+                for i, o in enumerate(outs):
+                    if 'b' in omodes[i]: o.write(line)
+                    else:                o.write(line.decode('utf-8'))
 
         t = threading.Thread(target=realForward)
         t.daemon = True
-- 
GitLab