From 871bc4afe9746af25ef7b05aecd2762d01c27681 Mon Sep 17 00:00:00 2001 From: Harshad Sharma Date: Fri, 16 Jun 2017 22:45:26 +0530 Subject: [PATCH] Add a shell command example. --- examples/shell.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 examples/shell.py diff --git a/examples/shell.py b/examples/shell.py new file mode 100755 index 0000000..bd03339 --- /dev/null +++ b/examples/shell.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# coding=utf-8 +import subprocess + +from qutescript import userscript +from qutescript.cli import parser + +parser.add_argument('-c', + action='store', + help='Command to execute.', + default='') + + +@userscript +def shell_command(request): + args = parser.parse_args() + if not args.c: + request.send_text("Please specify a command: {} -c'uname -a' ".format(request.script_name)) + return + r = subprocess.check_output(args=args.c.split(' ')) + request.send_text(r) + + +if __name__ == '__main__': + shell_command()