flush stdout and sterr before waiting for return code