shell_command: check the return code of the proc for success
Add a "get_return_code" method that allows users to fetch the return code after the shell command has executed. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
77f79fcc20
commit
2e44766e1e
|
@ -20,6 +20,7 @@ class ShellCommand:
|
||||||
self.command = shlex.split(cmd)
|
self.command = shlex.split(cmd)
|
||||||
self.partial_output = b""
|
self.partial_output = b""
|
||||||
self.cancelled = False
|
self.cancelled = False
|
||||||
|
self.return_code = None
|
||||||
|
|
||||||
def _process_output(self, fd, events):
|
def _process_output(self, fd, events):
|
||||||
if events & IOLoop.ERROR:
|
if events & IOLoop.ERROR:
|
||||||
|
@ -40,8 +41,11 @@ class ShellCommand:
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self.cancelled = True
|
self.cancelled = True
|
||||||
|
|
||||||
|
def get_return_code(self):
|
||||||
|
return self.return_code
|
||||||
|
|
||||||
async def run(self, timeout=2., verbose=True):
|
async def run(self, timeout=2., verbose=True):
|
||||||
fd = None
|
self.return_code = fd = None
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
# Never timeout
|
# Never timeout
|
||||||
timeout = 9999999999999999.
|
timeout = 9999999999999999.
|
||||||
|
@ -87,7 +91,8 @@ class ShellCommand:
|
||||||
msg = f"Command ({self.name}) timed out"
|
msg = f"Command ({self.name}) timed out"
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
self.io_loop.remove_handler(fd)
|
self.io_loop.remove_handler(fd)
|
||||||
return complete
|
self.return_code = proc.returncode
|
||||||
|
return self.return_code == 0 and complete
|
||||||
|
|
||||||
async def run_with_response(self, timeout=2.):
|
async def run_with_response(self, timeout=2.):
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Reference in New Issue