From 165f85f8dc1556281b86ebde53e680c3f8e1d7b7 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 4 Feb 2021 01:43:51 +0100 Subject: [PATCH] Added support for background shell commands --- platypush/plugins/shell/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/shell/__init__.py b/platypush/plugins/shell/__init__.py index b6f7b8c98..dfb100186 100644 --- a/platypush/plugins/shell/__init__.py +++ b/platypush/plugins/shell/__init__.py @@ -9,17 +9,21 @@ class ShellPlugin(Plugin): """ @action - def exec(self, cmd, ignore_errors=False): + def exec(self, cmd, background=False, ignore_errors=False): """ Execute a command. :param cmd: Command to execute :type cmd: str + :param background: If set to True, execute the process in the background, otherwise wait for the process termination and return its output (deafult: False). :param ignore_errors: If set, then any errors in the command execution will be ignored. Otherwise a RuntimeError will be thrown (default value: False) :returns: A response object where the ``output`` field will contain the command output as a string, and the ``errors`` field will contain whatever was sent to stderr. """ + if background: + subprocess.Popen(cmd, shell=True) + try: return subprocess.check_output( cmd, stderr=subprocess.STDOUT, shell=True).decode('utf-8')