Hello everyone,
I am facing a problem with this code. Actually my program should create a new Shell that takes the hole path to a bin command (/bin/ls , /bin/date ...) so it can execute it by using the function execl()
I succeeded in creating the new Shell that works great but I still have a problem with using execl()
Here's my code :
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int pid, longueur;
char tab[TABSIZE], *s;
int r;
for (;;) {
fputs("small_shell...> ", stdout);
s = fgets(tab, TABSIZE, stdin);
if (s == NULL) {
fprintf(stderr, "End Shell\n");
exit(EXIT_SUCCESS);
}
longueur = strlen(s);
tab[longueur - 1] = '\0';
pid = fork();
switch (pid) {
case -1:
break;
case 0:
r = execl(tab, (char*) NULL);
if (r==-1) {
fprintf(stderr, "Error in exec\n");
}
default:
wait(NULL);
}
}
}
when I write /bin/date in the "small shell" for example, it tells me that "A NULL argv[0] was passed through an exec system call."
Does anyone has an idea how to solve this ?