diff options
author | hut <hut@lavabit.com> | 2010-05-13 19:38:44 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-05-13 19:38:44 +0200 |
commit | f623ef5be7a00474ba2098ff2d23adfff0370c79 (patch) | |
tree | 18cf258c242ad4e1f0ade321e2d2292b0d29a4e1 /ranger/ext | |
parent | 37aac04b762d865e07d051d3606f009407889538 (diff) | |
download | ranger-f623ef5be7a00474ba2098ff2d23adfff0370c79.tar.gz |
Added ranger.ext.spawn which runs programs and returns their stdout
Diffstat (limited to 'ranger/ext')
-rw-r--r-- | ranger/ext/spawn.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py new file mode 100644 index 00000000..9723c1ed --- /dev/null +++ b/ranger/ext/spawn.py @@ -0,0 +1,27 @@ +# Copyright (C) 2009, 2010 Roman Zimbelmann <romanz@lavabit.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from subprocess import Popen, PIPE +ENCODING = 'utf-8' + +def spawn(*args): + """Runs a program, waits for its termination and returns its stdout""" + if len(args) == 1: + popen_arguments = args[0] + else: + popen_arguments = args + process = Popen(popen_arguments, stdout=PIPE) + stdout, stderr = process.communicate() + return stdout.decode(ENCODING) |