how do I exec() a script

Wolfgang G. Kuehnel caxwgk at pkinbg.UUCP
Thu Jun 28 19:43:58 AEST 1990


>From article <661 at kps.UUCP>, by llj at kps.UUCP (Leif Ljung /DP):
> I have a program that I want to do a general exec(2) sometimes
> executing a binary program, sometimes a shell-script preferably
> using PATH.
> Say I have the program `prog' - if this is a script I add the
> '#! /bin/sh' at the top. Can I exec(2) that? No.
> The system is a Pyramid running BSD4.3.
> Any clues?

I remember that we've done this using execve() after forking a program.
The program fork()ed and the child process execve()ed a /bin/sh-script.
We put '#! /bin/sh' at the top line and that worked.
We had to make sure that the arguments to execve() were correct:
*path had to be a full path *containing the file name at the end*
**argv[0] had to be the filename (again)
**envp could be point to NULL
The script had to be executeable for the effective uid of the forked
child process. We were working under SunOs 4.0.3, which should make
no difference to BSD4.3 in this respect.

Greetings
	Wolfgang Kuehnel
	Philips Kommunikations Industrie AG
	Nuernberg / West Germany



More information about the Comp.lang.c mailing list