Fix command execute function to support Python 3