joshuatree 0 Newbie Poster

Hi all,
I have a problem with my implementation of a unix shell, I'm hoping someone can point me straight...
In my shell program, I collect and parse a user's entry from the command line and dump it into an array like getopts(). I then call fork() and execvp(args[0],args)
((i.e. args[0] == ls ,args[1] == -l))
to get the other process to run the command, like ls -l .

What I'm having problems with is how to deal with improper command entry and the passing of this to execvp? The parent process currently waits(stat_val) for the child and I examine the WIFEXITED(stat_val) status to inform user of " command not found". Unfortunately, it only catches the case where I hit enter with no command line entry.... hitting any key like "j" then enter doesn't, return a problem.
Does anyone have any suggestions....?????
here's what i'm rambling about:

switch(child)
{
case -1:
perror("fork failed");
exit(0);
case 0:
if(args != NULL){
execvp(args[0],args);
}
exit(0);
default:
status = 0;
if (background == 0)   //running cmd in ForeGnd, so wait
wait(&status);
if(WIFEXITED(status) == 0)
printf("*** %s: command not found\n",args[0]);
if (background != 0)     //running cmd in BckGrnd, it's a
//  race
printf("\n  it's running in bkgrnd...\n");
break;
}


/* the steps are:
(1) fork a child process using fork()
(2) the child process invokes execvp()
(3) if background == 1, the parent will wait,
otherwise returns to the setup() function. */
////////////////////////////////////
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.