2012-08-08 3 views
0

쉘을 만들었고 system (1)을 사용할 때 작동하지만 스펙에서는 그렇지 않습니다. 끝에 execvp를 사용하려고하는데 실제로 어떻게해야하는지 잘 모르겠습니다. 도움이 될만한 기회가 주어질 것입니다.execvp 및 me; 나는 그것을 어떻게 작동시킬 수 있습니까?

코드 - 기본적>

char *token = NULL; 
char line[LINE_MAX]; 
char *line2 = NULL; 
char *tempraryToken = NULL; 
char *command = NULL; 
char args[LINE_MAX];  

int numSpaces = 0; 
int i; 
int strleng = 0; 
while(1) 
{ 
    if(scanf(" %[^\n]", line) > 0)) //prune off the newline char 
     token = strtok(line, ";") //break up different commands 
             //on the same line by ; 
     do{ 
      strleng = strlen(token); 
      for(i = 0; i < strleng; i++) 
      { 
       if(token[i] == ' ') numSpaces++; //find out if there are spaces 
      } 
      i = 0; 
      if(numSpaces >= 1) //if there are spaces 
      { 
       line2 = token; 
       temporaryToken = strtok(line2, " ") //break by spaces 
       do{ 
        //if it's before any spaces 
        if(i == 0){ 
         command = temporaryToken; 
        } 
        else strcat(args, temporaryToken); 
       strtok(NULL, " "); 
       while (temporaryToken != NULL); 
      } 
     execvp(command, args); //this could be any of the exe commands 
           //that's what I'm looking for 
     token = strtok(NULL, ";") //move to next token 
     while(token != NULL); 
} 
+1

귀하의 질문은 무엇입니까? – DevSolar

+0

프로세스가 완료 될 때까지 fork() 및 waitpid를 사용하는 것이 좋지 않습니까? – stetro

+0

나는이 질문을 표현하는 것이 끔찍합니다. 여기에서 사용할 올바른 exe 명령을 찾고 있습니다. –

답변

3

, 당신은 부모에 대한 자녀의 execvpwait 또는 waitpid를 실행하여 프로세스를 fork 필요 execvp 후 계속 실행합니다. 이 점을 염두에두고 자신의 연구를 수행하십시오 ;-)

+0

또한 올바른 입력과 출력을 처리해야합니다! – stetro

+1

네, 입력과 출력과 통신해야 할 필요가 있다면 말이죠. –