//æ¬å½æ°æ§è¡exepathæå®çç¨åº //æ§è¡æåå失败æ æ³è¿å int execute_new(const char *exepath,const char *arg,unsigned int &retpid) { if(exepath == NULL) { return 0; } int argcount=0; char *argv[1024]={0}; char argsave[1024]={0}; char *argline = argsave; argv[0] = (char *)exepath; argcount++; ////////////åå²åæååæ°,ä½ä¸ºexecvpå½æ°çåæ° if(arg != NULL) { strncpy(argsave,arg,1024-1); int is_find_space = -1; //-1, if(*argline != ' ') { argv[argcount] = (char *)argline; argcount++; } while(*argline != '\0') { if(*argline == ' ' && *(argline+1) != ' ' && *(argline+1) != '\0') { argv[argcount] = (char *)(argline+1); argcount++; } if(*argline == ' ') { *argline='\0'; } argline++; } } pid_t pid; int status; if((pid = fork())<0){ status = -1; } else if(pid == 0){ execv(exepath,argv); _exit(127); //åè¿ç¨æ£å¸¸æ§è¡åä¸ä¼æ§è¡æ¤è¯å¥ } else{ retpid = pid; waitpid(pid, &status, WNOHANG|WUNTRACED); } return status; }
温馨提示:答案为网友推荐,仅供参考