Ramjets can only operate at relatively high air speeds. The incoming air is compressed by a constricted mouth. Without that pressure, there is nothing to stop the exhaust from going out both ends.
So the short answer to your question is: the incoming air is compressed, raising the pressure, and acts as a barrier for the exhaust, causing it to only vent aft.