Skip to content

Commit e8f875d

Browse files
authored
[Container] az container exec: Fix exception when stdin is not a tty (#30397)
1 parent bc2b1ce commit e8f875d

File tree

1 file changed

+11
-4
lines changed
  • src/azure-cli/azure/cli/command_modules/container

1 file changed

+11
-4
lines changed

src/azure-cli/azure/cli/command_modules/container/custom.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,16 @@ def _on_ws_open_windows(ws):
10031003

10041004
def _start_exec_pipe_linux(web_socket_uri, password):
10051005
stdin_fd = sys.stdin.fileno()
1006-
old_tty = termios.tcgetattr(stdin_fd)
1006+
try:
1007+
old_tty = termios.tcgetattr(stdin_fd)
1008+
has_tty = True
1009+
except termios.error:
1010+
old_tty = None
1011+
has_tty = False
10071012
old_winch_handler = signal.getsignal(signal.SIGWINCH)
1008-
tty.setraw(stdin_fd)
1009-
tty.setcbreak(stdin_fd)
1013+
if has_tty:
1014+
tty.setraw(stdin_fd)
1015+
tty.setcbreak(stdin_fd)
10101016
buff = bytearray()
10111017
lock = threading.Lock()
10121018

@@ -1018,7 +1024,8 @@ def _on_ws_open_linux(ws):
10181024
flushKeyboard.start()
10191025
ws = websocket.WebSocketApp(web_socket_uri, on_open=_on_ws_open_linux, on_message=_on_ws_msg)
10201026
ws.run_forever()
1021-
termios.tcsetattr(stdin_fd, termios.TCSADRAIN, old_tty)
1027+
if has_tty:
1028+
termios.tcsetattr(stdin_fd, termios.TCSADRAIN, old_tty)
10221029
signal.signal(signal.SIGWINCH, old_winch_handler)
10231030

10241031

0 commit comments

Comments
 (0)