From 114dd90baf8d300e7ba6f058fe42a0d2ebdbd223 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 28 Sep 2007 15:37:40 -0400 Subject: Make the command module use subprocess to capture stdin/stdout and return them to the caller. --- modules/command.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'modules/command.py') diff --git a/modules/command.py b/modules/command.py index d862199..5dc0292 100644 --- a/modules/command.py +++ b/modules/command.py @@ -25,8 +25,16 @@ class Command(func_module.FuncModule): func_module.FuncModule.__init__(self) def run(self, command): - return sub_process.call(command.split()) + """ + Runs a command, returning the return code, stdout, and stderr as a tuple. + NOT FOR USE WITH INTERACTIVE COMMANDS. + """ + cmdref = sub_process.Popen(command.split(),stdout=sub_process.PIPE,stderr=sub_process.PIPE, shell=False) + data = cmdref.communicate() + return (cmdref.returncode, data[0], data[1]) methods = Command() register_rpc = methods.register_rpc + + -- cgit