簡単なシェルのようなものを作りたいのですが、プロセスが複製されていないもしくは、シェルを実行するコマンドがうまくいきません・・・
C
1#include<stdio.h> 2#include<unistd.h> 3#include <string.h> 4#include<sys/wait.h> 5 6int main(){ 7 char command[100]; 8 char p[3][10]; 9 printf(">"); 10 fgets(command,100,stdin); 11 12 char *tp = strtok(command," "); 13 strcpy(p[1],tp); 14 int count=1; 15 while(tp!=NULL){ 16 tp=strtok(NULL, " "); 17 count+=1; 18 if(tp!=NULL)strcpy(p[count],tp); 19 } 20 pid_t pid = fork(); 21 if (pid > 0 ){ 22 int ret; 23 waitpid(pid,&ret,0); 24 } 25 else{ 26 char* cmd[]={p[1],p[2],NULL}; 27 execvp(cmd[0], cmd); 28 } 29 30 }
入力文字の切り分けはうまくいっているようなのですが、肝心のシェルがうまくいきません・・・
よろしくお願いいたします。
fgetsの改行コード
回答2件
あなたの回答
tips
プレビュー