platypush/platypush/plugins/shell/__init__.py

22 lines
496 B
Python
Raw Normal View History

2017-10-31 09:20:35 +01:00
import subprocess
from platypush.message.response import Response
2017-10-31 09:20:35 +01:00
from .. import Plugin
class ShellPlugin(Plugin):
def exec(self, cmd):
2017-10-31 09:20:35 +01:00
output = None
errors = []
2017-10-31 09:20:35 +01:00
try:
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, shell=True).decode('utf-8')
2017-10-31 09:20:35 +01:00
except subprocess.CalledProcessError as e:
errors = [e.output.decode('utf-8')]
2017-10-31 09:20:35 +01:00
return Response(output=output, errors=errors)
2017-10-31 09:20:35 +01:00
# vim:sw=4:ts=4:et: