On some systems the which command can emit messages into stderr. For example, for debianutils 5.5-1 package in Debian Sid:
# which cat
/usr/bin/which: this version of `which' is deprecated; use `command -v' in scripts instead.
/bin/cat
Although such messages are harmless, they could distract developers needlessly (see bitcoin/bitcoin#24056).
Fixes bitcoin/bitcoin#24056.