diff options
Diffstat (limited to 'ranger/applications.py')
-rw-r--r-- | ranger/applications.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/ranger/applications.py b/ranger/applications.py index fd977c43..ca934920 100644 --- a/ranger/applications.py +++ b/ranger/applications.py @@ -13,3 +13,43 @@ class Applications(object): def all(self): return [x for x in self.__dict__ if x.startswith('app_')] +import os +null = open(os.devnull, 'a') + +def run(*args, **kw): + from subprocess import Popen + from subprocess import PIPE + from ranger.ext import waitpid_no_intr + + flags, fm = kw['flags'], kw['fm'] + for flag in flags: + if ord(flag) <= 90: + bad = flag + flag.lower() + flags = ''.join(c for c in flags if c not in bad) + + args = map(str, args) + popen_kw = {} + + if kw['stdin'] is not None: + popen_kw['stdin'] = kw['stdin'] + + if 's' in flags or 'd' in flags: + popen_kw['stdout'] = popen_kw['stderr'] = popen_kw['stdin'] = null + + if 'p' in flags: + popen_kw['stdout'] = PIPE + process1 = Popen(args, **popen_kw) + kw['stdin'] = process1.stdout + kw['files'] = () + kw['flags'] = ''.join(f for f in kw['flags'] if f in 'd') + process2 = kw['apps'].app_pager(**kw) + return process2 + if 'd' in flags: + process = Popen(args, **popen_kw) + return process + else: + fm.ui.exit() + p = Popen(args, **popen_kw) + waitpid_no_intr(p.pid) + fm.ui.initialize() + return p |