shell_command: add run_with_response() method
This method collects the entire response and returns it with the call. Suitable for commands that produce little output. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
706d86dd21
commit
116c1e9f29
|
@ -93,6 +93,20 @@ class ShellCommand:
|
|||
self.io_loop.remove_handler(fd)
|
||||
return complete
|
||||
|
||||
async def run_with_response(self, timeout=2.):
|
||||
result = []
|
||||
|
||||
def cb(data):
|
||||
data = data.strip()
|
||||
if data:
|
||||
result.append(data.decode())
|
||||
prev_cb = self.output_cb
|
||||
self.output_cb = cb
|
||||
await self.run(timeout)
|
||||
self.output_cb = prev_cb
|
||||
return "\n".join(result)
|
||||
|
||||
|
||||
class ShellCommandFactory:
|
||||
def build_shell_command(self, cmd, callback):
|
||||
return ShellCommand(cmd, callback)
|
||||
|
|
Loading…
Reference in New Issue