optimized cmd_exec() function for drawing