Applies to any pre-nuclear sub really. It seems like it would be impractical to store it all on-board but venting would give away the sub's position.
As always, uboat.net and uboatarchive.net are some of the best resources for U-boat details and operations. The conventional and main form of exhaust for the Type VII and IX (the main U-boat classes of the war) was towards the vessels' stern. Through a series of ducted pipelines exhaust would be vented out of the vessel through a streamlined fairing on the hull. This system was only used when the sub was surfaced, which was the majority of the time as the battery life of these submarines precluded extended cruises underwater. The vulnerability of u-boats attack when on the surface led to the adaptation of a Dutch invention, the Schnorchel. This would allow the subs to cruise underwater on their diesels. The Schnorchel though often exacerbated habitability issues in the cramped subs because if they were operated in heavy sea swells, water could seep in and create a discomforting change in air pressure.
Pretty much exactly what /u/kieslowskifan said, but I'd emphasize what he/she kind of said as an afterthought -- the diesels would only run on the surface, subs would use battery power when submerged. Or, in some cases, use the snorkel system, but that left subs fairly vulnerable on the surface.
It's probably better to think of pre-nuclear subs as "submersibles" rather than submarines. They were essentially oceangoing boats that could submerge to sneak up on a target or to avoid detection.