It varies, but not all of the carts will remain open until the park closes. I know the popcorn cart in NOS often closes before the parks (anywhere starting 90 minutes before the park closes); I think it's the same for the one in Frontierland and Tomorrowland. I think most of them do stop when the park closes at the very latest (I know that the popcorn cart in Town Square does not remain open even through the MS shops remain open an hour after closes). Personally, to be safe, I would plan to pick-up any snack cart offerings at least one hour before the park closes.