about summary refs log tree commit diff stats
path: root/ranger/ext/spawn.py
diff options
context:
space:
mode:
Diffstat (limited to 'ranger/ext/spawn.py')
-rw-r--r--ranger/ext/spawn.py41
1 files changed, 37 insertions, 4 deletions
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py
index b07dd2e0..393d48d9 100644
--- a/ranger/ext/spawn.py
+++ b/ranger/ext/spawn.py
@@ -5,15 +5,45 @@ from subprocess import Popen, PIPE, CalledProcessError
 ENCODING = 'utf-8'
 
 
-def spawn(*args):
-    """Runs a program, waits for its termination and returns its stdout"""
+def spawn(*args, **kwargs):
+    """Runs a program, waits for its termination and returns its stdout
+
+    This function is similar to python 2.7's subprocess.check_output,
+    but is favored due to python 2.6 compatibility.
+
+    The arguments may be:
+
+        spawn(string)
+        spawn(command, arg1, arg2...)
+        spawn([command, arg1, arg2])
+
+    The string will be run through a shell, otherwise the command is executed
+    directly.
+
+    The keyword argument "decode" determines if the output shall be decoded
+    with the encoding '%s'.
+
+    Further keyword arguments are passed to Popen.
+    """ % (ENCODING, )
+
     if len(args) == 1:
         popen_arguments = args[0]
         shell = isinstance(popen_arguments, str)
     else:
         popen_arguments = args
         shell = False
-    process = Popen(popen_arguments, stdout=PIPE, shell=shell)
+
+    if 'decode' in kwargs:
+        do_decode = kwargs['decode']
+        del kwargs['decode']
+    else:
+        do_decode = True
+    if 'stdout' not in kwargs:
+        kwargs['stdout'] = PIPE
+    if 'shell' not in kwargs:
+        kwargs['shell'] = shell
+
+    process = Popen(popen_arguments, **kwargs)
     stdout, stderr = process.communicate()
     return_value = process.poll()
     if return_value:
@@ -21,4 +51,7 @@ def spawn(*args):
         error.output = stdout
         raise error
 
-    return stdout.decode(ENCODING)
+    if do_decode:
+        return stdout.decode(ENCODING)
+    else:
+        return stdout
:04 -0400 committer Ben Morrison <ben@gbmor.dev> 2020-06-30 02:19:24 -0400 reducing use of php in favor of shellscript build' href='/tilde/site/commit/html/faq.html?id=5db8118b173d9ff0c4bc2d2c55e72967090ad991'>5db8118 ^
545d7f6 ^



5db8118 ^


545d7f6 ^


5db8118 ^





2ebe2cc ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63