Safely run exec in a loop.