handle exit code from spawn correctly