ENOTTY
Linux / POSIXERRORNotableDeviceHIGH confidence
Inappropriate ioctl for Device
Production Risk
Common in CLI tools that assume an interactive terminal but are run from cron or CI pipelines.
What this means
ENOTTY (errno 25) is returned when an ioctl() request is made on a file descriptor that is not a terminal, or when a terminal control function (like isatty(), tcgetattr()) is called on a non-TTY file descriptor.
Why it happens
- 1Calling isatty() or tcgetattr() on a pipe, file, or socket instead of a terminal
- 2Running a program that uses terminal-specific ioctls on a file descriptor redirected from a pipe or file
- 3Sending ioctl(TIOCGWINSZ) to get terminal dimensions on a non-terminal fd
How to reproduce
Checking if a piped stdin is a TTY.
trigger — this will error
trigger — this will error
import os, sys # When stdin is a pipe: os.tcgetpgrp(sys.stdin.fileno()) # OSError: [Errno 25] Inappropriate ioctl for device
expected output
OSError: [Errno 25] Inappropriate ioctl for device
Fix
Check isatty() before making terminal-specific calls
WHEN When code may run with stdin/stdout redirected
Check isatty() before making terminal-specific calls
import sys, os
if sys.stdout.isatty():
# safe to use terminal-specific features
rows, cols = os.get_terminal_size()
else:
# running in a pipe or redirect — skip terminal features
rows, cols = 24, 80Why this works
isatty() returns False for pipes, files, and sockets. Guard all terminal-specific code with this check to handle non-interactive execution gracefully.
Sources
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev