write output using a callback