用 C 制作 shell
making a shell with C
我正在尝试使用 C 创建一个 shell 作为家庭作业,但我的 execvp() 不起作用。它不执行 ls。我在虚拟机 lubuntu 32 上工作
Thas 我输出任何我的错误信息!
if(pid==0){
printf("child");
char **tokens=tokenizer(hey)//hey is from fgets. tokenizer is fine
printer(tokens);
//execute ls
execvp( ls_args[0], ls_args);
//only get here if exec failed
perror("execv failed");
return 2; //return error status }
您的第三个参数 (a[2]
) 末尾有一个换行符。 ls
因此抱怨它无法在您的主目录下找到以单个换行符命名的目录。修复您的命令解析以不包含换行符。
我正在尝试使用 C 创建一个 shell 作为家庭作业,但我的 execvp() 不起作用。它不执行 ls。我在虚拟机 lubuntu 32 上工作
Thas 我输出任何我的错误信息!
if(pid==0){
printf("child");
char **tokens=tokenizer(hey)//hey is from fgets. tokenizer is fine
printer(tokens);
//execute ls
execvp( ls_args[0], ls_args);
//only get here if exec failed
perror("execv failed");
return 2; //return error status }
您的第三个参数 (a[2]
) 末尾有一个换行符。 ls
因此抱怨它无法在您的主目录下找到以单个换行符命名的目录。修复您的命令解析以不包含换行符。