checkcmd function