사용자는 줄을 읽고 첫 단어를 execvp의 명령으로 유지합니다.execvp() 사용 방법
하자 그가 입력 할 것이라고 "고양이 file.txt" ... 고양이 명령이 될 것입니다. 그러나 나는 이것을 사용하는 방법을 모르겠다. execvp()
, 나는 튜토리얼을 읽었지만 여전히 이해하지 못했다.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char *buf;
char command[32];
char name[32];
char *pointer;
char line[80];
printf(">");
while((buf = readline(""))!=NULL){
if (strcmp(buf,"exit")==0)
break;
if(buf[0]!=NULL)
add_history(buf);
pointer = strtok(buf, " ");
if(pointer != NULL){
strcpy(command, pointer);
}
pid_t pid;
int status;
if ((pid = fork()) < 0) {
printf("*** ERROR: forking child process failed\n");
exit(1);
}
else if (pid == 0) {
if (execvp(command, buf) < 0) {
printf("*** ERROR: exec failed\n");
exit(1);
}
}
else
while (wait(&status) != pid)
;
free(buf);
printf(">");
}///end While
return 0;
}
무슨 뜻 이죠 당신이 그것을 얻을하지 않습니다? 더 구체적으로 말하십시오. – SSC
[RTFM] (http://linux.die.net/man/3/execvp) –
execvp에서 어떤 인수를 전달해야하는지 모르겠습니다. – Axl