How to handle inputs in a C shell program during exec
- by hits_lucky
I am currently writing my own shell program. This simple shell can just execute commands.
When executing commands like vi or calc which require input from the terminal , the command is getting executed and is waiting for the input from the user. But I am unable to give any input on the screen.
How should the input be handled during the fork and exec.
Here is the piece of code which is executing commands:
if((pid = fork()) < 0)
{
perror("Fork failed");
exit(errno);
}
if(pid == 0)
{
// Child process
if(execvp(arguments[0], arguments) == -1)
{
child_status = errno;
switch(child_status)
{
case ENOENT:
printf(" command not found \n");
break;
}
exit(errno);
}
}
else
{
// parent process
int wait_stat;
if(waitpid(pid , &wait_stat, WNOHANG) == -1)
{
printf(" waitpid failed \n");
return;
}
}
}
~
Thanks,