summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/linemode.py10
-rw-r--r--ranger/ext/spawn.py8
2 files changed, 9 insertions, 9 deletions
diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py
index f63cb142..a8ce4e6d 100644
--- a/ranger/core/linemode.py
+++ b/ranger/core/linemode.py
@@ -7,6 +7,7 @@ import sys
 from abc import *
 from datetime import datetime
 from ranger.ext.human_readable import human_readable
+from ranger.ext.spawn import spawn
 
 DEFAULT_LINEMODE = "filename"
 
@@ -99,14 +100,7 @@ class FileInfoLinemode(LinemodeBase):
         if not file.is_directory:
             from subprocess import Popen, PIPE, CalledProcessError
             try:
-                process = Popen(["file", "-bL", file.path], stdout=PIPE)
-                output, unused_err = process.communicate()
-                retcode = process.poll()
-                if retcode:
-                    error = subprocess.CalledProcessError(retcode, "file")
-                    error.output = output
-                    raise error
-                fileinfo = output.strip()
+                fileinfo = spawn(["file", "-bL", file.path]).strip()
             except CalledProcessError:
                 return "unknown"
             if sys.version_info[0] >= 3:
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py
index 7c5c921c..b07dd2e0 100644
--- a/ranger/ext/spawn.py
+++ b/ranger/ext/spawn.py
@@ -1,7 +1,7 @@
 # This file is part of ranger, the console file manager.
 # License: GNU GPL version 3, see the file "AUTHORS" for details.
 
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, CalledProcessError
 ENCODING = 'utf-8'
 
 
@@ -15,4 +15,10 @@ def spawn(*args):
         shell = False
     process = Popen(popen_arguments, stdout=PIPE, shell=shell)
     stdout, stderr = process.communicate()
+    return_value = process.poll()
+    if return_value:
+        error = CalledProcessError(return_value, popen_arguments[0])
+        error.output = stdout
+        raise error
+
     return stdout.decode(ENCODING)