Absolutely. There is a device called a bore evacuator which has been in service for a long time on large caliber guns. Its purpose is to draw combustion gas out through the muzzle after the shot cycle is over, so that said gas (which is usually toxic) doesn't flow backwards out the breech and into the crew compartment (assuming the gun is mounted on a vehicle like a tank or self-propelled howitzer). The picture below shows a bore evacuator on on an Abrams tank. It is the bulge in the middle of the main gun barrel with the words "99 Problems" faintly visible on it.
The way it works is simple; after the bullet passes the bore evacuator, the high-pressure combustion gas behind the bullet is allowed to flow into the bore evacuator through small holes. After the bullet exits the gun, the pressure in the tube begins to drop, eventually going below the pressure in the evacuator. The gas then begins to flow out of the evacuator into the tube through holes that are slightly angled towards the muzzle. The resulting discharge induces gas flow towards the muzzle and creates a slight vacuum at the breech. When the breech is opened, hardly any combustion gas escapes into the crew compartment due to this forward flow.
The bore evacuator stores the gas for only a few milliseconds, but it should not be difficult to store it longer (a few seconds or minutes) by using check valves. In fact some bore evacuators in service do use check valves at the inlet to increase their effectiveness. I don't know how much gas you need to store, but you may not need to close off the barrel completely; you may be able to harvest enough gas just during the normal shot cycle, before the bullet exits the gun.
There is also a German recoilless rifle called the "Armbrust":
It uses captive pistons to completely hold the propellant combustion gas inside the weapon after firing. It's a one-use weapon though, which may not work for what you're doing.