twister: Set stdin explicitly on stty calls

stty operates on the file descriptor from stdin, but we want to operate
on stdout. If stdin and stdout are not the same tty then stty prints an
error.

Redirect stdout to stdin for stty calls.

Tested by running twister -T tests/subsys/shell </dev/null

Signed-off-by: Jeremy Bettis <jbettis@google.com>
This commit is contained in:
Jeremy Bettis 2022-08-24 12:44:05 -06:00 committed by Carles Cufí
commit 562b291704
2 changed files with 3 additions and 3 deletions

View file

@ -286,7 +286,7 @@ class BinaryHandler(Handler):
# FIXME: This is needed when killing the simulator, the console is
# garbled and needs to be reset. Did not find a better way to do that.
if sys.stdout.isatty():
subprocess.call(["stty", "sane"])
subprocess.call(["stty", "sane"], stdin=sys.stdout)
if harness.is_pytest:
harness.pytest_run(self.log)
@ -839,7 +839,7 @@ class QEMUHandler(Handler):
logger.debug("Spawning QEMUHandler Thread for %s" % self.name)
self.thread.start()
if sys.stdout.isatty():
subprocess.call(["stty", "sane"])
subprocess.call(["stty", "sane"], stdin=sys.stdout)
logger.debug("Running %s (%s)" % (self.name, self.type_str))
command = [self.generator_cmd]

View file

@ -406,6 +406,6 @@ if __name__ == "__main__":
finally:
if (os.name != "nt") and os.isatty(1):
# (OS is not Windows) and (stdout is interactive)
os.system("stty sane")
os.system("stty sane <&1")
sys.exit(ret)