Reputation: 44256
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.
Upvotes: 3
Views: 1000
Reputation: 40884
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.
Upvotes: 2