Factor out the "execute or trash output" pattern.