summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-17 18:58:55 +0100
committerhut <hut@lavabit.com>2013-02-17 18:58:55 +0100
commitc6cfbaf2dae5d5aadfabfa82e48a1ca7d3ae0708 (patch)
tree20e0d6355d9f26aedf53c28cf319a520a50fa5cc /ranger
parent096fd48b21ad1c9c5657bbec9d2a26ea55d22c62 (diff)
downloadranger-c6cfbaf2dae5d5aadfabfa82e48a1ca7d3ae0708.tar.gz
core.loader: Fix passing stdin to commands in python3
Diffstat (limited to 'ranger')
-rw-r--r--ranger/core/loader.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index bae19e9e..d5e5e615 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -133,6 +133,7 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
         self.kill_on_pause = kill_on_pause
 
     def generate(self):
+        py3 = sys.version >= '3'
         if self.input:
             stdin = PIPE
         else:
@@ -141,12 +142,17 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
                 stdout=PIPE, stderr=PIPE, stdin=stdin)
         self.signal_emit('before', process=process, loader=self)
         if self.input:
+            if py3:
+                import io
+                stdin = io.TextIOWrapper(process.stdin)
+            else:
+                stdin = process.stdin
             try:
-                process.stdin.write(self.input)
+                stdin.write(self.input)
             except IOError as e:
                 if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
                     raise
-            process.stdin.close()
+            stdin.close()
         if self.silent and not self.read:
             while process.poll() is None:
                 yield
@@ -154,7 +160,6 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
                     break
                 sleep(0.03)
         else:
-            py3 = sys.version >= '3'
             selectlist = []
             if self.read:
                 selectlist.append(process.stdout)