[trivial] some messages are written to stdout instead of stderr

Bug #2061951 reported by Tom Levy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
command-not-found
New
Undecided
Unassigned

Bug Description

CommandNotFound.py writes some messages (such as "Please ask your administrator.") to standard output instead of standard error. This can break scripts that run commands and expect standard output to be empty if the command is not installed. Patch attached.

The main bug was introduced in revision 216 (https://bazaar.launchpad.net/~ubuntu-core-dev/command-not-found/ubuntu/revision/216). The print() call in line 255 was split into two calls (lines 262 and 263), but the `file=` parameter was omitted from the second call.

The following lines in the latest revision write to standard output and I think should be changed to write to standard error by adding `file=self.output_fd` (see attached patch). The line numbers refer to https://bazaar.launchpad.net/~ubuntu-core-dev/command-not-found/ubuntu/view/278/CommandNotFound/CommandNotFound.py:

226: print(_("Please ask your administrator."))
240: print(_("Please ask your administrator."))
375: print("You also have python3 installed, you can run 'python3' instead.")
376: print("")

Full steps to reproduce:

```
# setup
docker run --rm -it ubuntu:22.04
apt update
apt install -y command-not-found bash-completion
apt update # populate command-not-found database
su -s /bin/bash nobody

# test
$ ruptime
Command 'ruptime' not found, but can be installed with:
apt install rwho
Please ask your administrator.
$ ruptime 2>/dev/null
Please ask your administrator.
```

For the last command, the expected behaviour is that no output will be written to the screen (all output should be written to stderr, which the last command redirects to /dev/null).

```
# versions
$ /usr/lib/command-not-found --version
0.3
$ dpkg -l command-not-found python3-commandnotfound
...
ii command-not-found 22.04.0 ...
ii python3-commandnotfound 22.04.0 ...
```

Revision history for this message
Tom Levy (tomlevy) wrote :
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.