쉘을 만들었고 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);
}
귀하의 질문은 무엇입니까? – DevSolar
프로세스가 완료 될 때까지 fork() 및 waitpid를 사용하는 것이 좋지 않습니까? – stetro
나는이 질문을 표현하는 것이 끔찍합니다. 여기에서 사용할 올바른 exe 명령을 찾고 있습니다. –