added stdout hook to redirect stdout to a string