in ioXt/uraniborg/scripts/python/syscall_wrapper.py [0:0]
def call_returnable_command(self, cmd):
"""Handles the type of calls that returns.
For these type of calls, we can just pull the results when the call ends.
Args:
cmd: The command to be executed.
"""
self.reset()
logger = self._logger
logger.debug("cmd: {}".format(cmd))
self.last_command = cmd
cmd_pid = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
self.return_code = cmd_pid.poll()
try:
line = cmd_pid.stdout.readline().decode("utf-8", "replace").strip()
if line:
self.result_final.append(line)
except KeyboardInterrupt:
self.error_occured = True
self.error_message = "Terminated by keyboard interrupt."
break
if not line and self.return_code is not None:
break
if self.return_code == 0:
return
# try to extract error message from stderr
logger.debug("return code: {}".format(self.return_code))
self.error_occured = True
self.error_final = []
while True:
try:
line = cmd_pid.stderr.readline().decode("utf-8", "replace").strip()
if line:
self.error_final.append(line)
except KeyboardInterrupt:
self.error_message = ("Error message extraction interrupted by keyboard"
" interrupt:")
break
if not line:
break
self.error_message = "\n".join(self.error_final)
return