diff --git a/invoke/terminals.py b/invoke/terminals.py index 4151ba5e..b54e2283 100644 --- a/invoke/terminals.py +++ b/invoke/terminals.py @@ -243,6 +243,7 @@ def bytes_to_read(input_: IO) -> int: # it's not a tty but has a fileno, or vice versa; neither is typically # going to work re: ioctl(). if not WINDOWS and isatty(input_) and has_fileno(input_): - fionread = fcntl.ioctl(input_, termios.FIONREAD, b" ") - return int(struct.unpack("h", fionread)[0]) + arg = bytes(bytearray(struct.calcsize("i"))) + fionread = fcntl.ioctl(input_, termios.FIONREAD, arg) + return int(struct.unpack("i", fionread)[0]) return 1 diff --git a/tests/runners.py b/tests/runners.py index bad5f15c..c32da5fe 100644 --- a/tests/runners.py +++ b/tests/runners.py @@ -1224,7 +1224,7 @@ def fake_ioctl(fd, cmd, buf): # This works since each mocked attr will still be its own mock # object with a distinct 'is' identity. if cmd is termios.FIONREAD: - return struct.pack("h", len(stdin_data)) + return struct.pack("i", len(stdin_data)) ioctl.side_effect = fake_ioctl # Set up our runner as one w/ mocked stdin writing (simplest way to