ユーザーからの特定のコマンドをサブストリングに分割しました。コードは次のとおりです。
int i;
char *line = malloc(BUFFER);
char *origLine = line;
fgets(line, 128, stdin); // get a line from stdin
// get complete diagnostics on the given string
lineData info = runDiagnostics(line);
char command[20];
sscanf(line, "%20s ", command);
line = strchr(line, ' ');
printf("The Command is: %s\n", command);
int currentCount = 0; // number of elements in the line
int *argumentsCount = ¤tCount; // pointer to that
// get the elements separated
char** arguments = separateLineGetElements(line,argumentsCount);
// here we call a method that would execute the commands
if (execvp(*arguments,*argumentsCount) < 0) // execute the command
{
printf("ERROR: exec failed\n");
exit(1);
}
でコマンドを実行するexecvp(*arguments,*argumentsCount)
と失敗します。
どうしたの ?
ありがとう 。
編集 :
ユーザーからの入力は:ですls > a.out
。したがって、3つの文字列があります。
ls
、、、>
そしてa.out
失敗します。