Skip to content

Don't prompt if stdin is not a terminal

Otherwise cnf can be easily crashed, in case commands are piped, and one of those commands are not installed. Example:

root@debian:~# apt install -y alsa-utils
root@debian:~# apt remove sox
root@debian:~# export COMMAND_NOT_FOUND_INSTALL_PROMPT=1

root@debian:~# cat /usr/share/sounds/alsa/Front_Left.wav | play -
Command 'play' not found, but can be installed with:
apt install sox
Do you want to install it? (N/y)Sorry, command-not-found has crashed! Please file a bug report at:
http://www.debian.org/Bugs/Reporting
Please include the following information with the report:

command-not-found version: 0.3
Python version: 3.11.2 final 0
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 12 (bookworm)
Release:	12
Codename:	bookworm
Exception information:

'utf-8' codec can't decode byte 0x80 in position 24: invalid start byte
Traceback (most recent call last):
  File "/usr/share/command-not-found/CommandNotFound/util.py", line 23, in crash_guard
    callback()
  File "/usr/lib/command-not-found", line 95, in main
    if not cnf.advise(args[0], options.ignore_installed) and not options.no_failure_msg:
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/command-not-found/CommandNotFound/CommandNotFound.py", line 362, in advise
    self.advice_single_deb_package(command, packages, snaps)
  File "/usr/share/command-not-found/CommandNotFound/CommandNotFound.py", line 229, in advice_single_deb_package
    self.install_prompt(packages[0][0])
  File "/usr/share/command-not-found/CommandNotFound/CommandNotFound.py", line 164, in install_prompt
    answer = input(prompt)
             ^^^^^^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 24: invalid start byte

Merge request reports

Loading