Seems that Open3.popen3
raises a Errno::ENOENT
exception if it doesn't find the command; so you just have to rescue from that exception:
require 'open3'
begin
Open3.popen3('non-existing command') do |stdin, stdout, stderr, thread|
end
rescue Errno::ENOENT
puts "command not found"
end
#=> outputs "command not found"