If the battery light comes on while driving, it means the alternator is not producing electricity and thus the car is running only on battery power. The safest thing to do when this light comes on is to pull over safely and try to locate the problem.
Once the battery light switches on, the car will only travel a short distance before coming to a complete stop. There is no way to tell just how long a car will continue for, but switching off electrical items such as the radio and air conditioning will help. To fix the problem, check that all the battery connections are in place and clean them to prevent charging problems. If this does not work, then the alternator belt or alternator likely needs to be replaced.