exec() with executable shell scripts
Kenneth Almquist
ka at june.cs.washington.edu
Sun Apr 23 19:40:31 AEST 1989
jiii at visdc.UUCP (John E Van Deusen III) writes:
> If you do not want to use [execlp or execvp], you have to do the
> following, (I have used execl for clarity):
>
> execl("/bin/sh", "sh", "-c", "/bin/true", 0);
More generally, you can write:
execl(program, (char *)0);
if (errno == ENOEXEC) { /* it's a shell procedure */
execl("/bin/sh", "sh", program, (char *)0);
perror("/bin/sh");
} else {
perror(program);
}
exit(2);
Note that if you write "0" in place of "(char *)0" this code will no
longer be machine independent
Kenneth Almquist
More information about the Comp.unix.wizards
mailing list