作者:sweet佳楠名人博客 | 来源:互联网 | 2023-10-12 13:55
Iamtryingtomakeatinyshell.MyproblemisthatwhenIcallexecvp()-Igeterrors.Forexampl
I am trying to make a tiny shell. My problem is that when I call execvp()
- I get errors. For example, when I type in ls -l
it returns ls: invalid option -- '
我想做一个小壳。我的问题是,当我调用execvp()时 - 我得到错误。例如,当我输入ls -l时,它返回ls:invalid选项 - '
Can someone, please, help me understand why I am getting this error? For my code, the function command split gets the user input, and splits them up into separate commands. Separate commands are seperated by ;
character.
请有人帮助我理解为什么我会收到此错误?对于我的代码,函数命令split获取用户输入,并将它们拆分为单独的命令。单独的命令分开;字符。
#include
#include
#include
#include
#include
#include
#include
#define MAX_CHARACTERS 512
#define HISTORY_SIZE 10
int commandSplit(char *c, char *a[], int t[]) {
int count = 0;
int total = 0;
char *temp[MAX_CHARACTERS];
char *readCommands = strtok(c, ";");
while(readCommands != NULL) {
printf("Reading full command: %s\n", readCommands);
temp[count] = readCommands;
count++;
readCommands = strtok(NULL, ";");
}
printf("Done reading full commands\n");
for(int i = 0; i ");
fgets(commands, MAX_CHARACTERS, stdin);
if(strlen(commands) == 0) continue;
numOfCommands = commandSplit(commands, args, tracker);
printf("There are %i commands!\n", numOfCommands);
if(strcmp(args[0], "exit") == 0) {
printf("Exiting\n");
exitProgram = 1;
continue;
}
int l = 0;
for(int i = 0; i
1 个解决方案