The following always fails:
import fcntl
import termios
buffer = bytearray(8)
fcntl.ioctl(2, termios.TIOCGWINSZ, buffer, True)
Always fails with:
Traceback (most recent call last):
File "testit.py", line 5, in <module>
fcntl.ioctl(2, termios.TIOCGWINSZ, buffer, True)
TypeError: ioctl requires a file or file descriptor, an integer and optionally an integer or buffer argument
termios.TIOCGWINSZ == 21523, an integerWhy? It executes fine in Python 3, but alas, we use Python 2 in production.
Edit: This is very similar to Python's issue #10345, except unlike the filer of that bug, I am using a mutable buffer.
The problem is that bytearray is not the buffer type you're looking for.
This works:
import fcntl
import termios
import array
buffer = array.array('h', [0]*8)
assert fcntl.ioctl(2, termios.TIOCGWINSZ, buffer, True) == 0
print buffer # first two bytes are set to terminal's height and width.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With