Run commands in a thread