【发布时间】:2014-02-22 11:49:16
【问题描述】:
我的任务是编写一个简单的 linux shell。我正在使用外部命令。我们需要使用 execv。
for (int i = 0; i < count; i++){
char path[1024];
strcpy(path, PATHS[i]); // PATHS is an array of cstrings, the paths in $PATH
strcat(path, "/");
strcat(path, command[0]); // command and commands are essentially the same
printf("%d %s",i,path); // they are essentially argv[]
if (!execv(path, commands)) // for ls -l $HOME
break; // commands[0] = ls [1] = -l [2] = my home dir
现在我只用 ls 测试它。 ls 完全按照它应该运行的方式运行,但程序在 execv 成功后立即关闭。有什么办法让我继续使用 execv 来检查路径是否正确,并让程序在 execv 成功后继续运行?
【问题讨论】: