Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!mcsun!unido!pkinbg!caxwgk@pkinbg.UUCP From: caxwgk@pkinbg.UUCP (Wolfgang G. Kuehnel) Newsgroups: comp.lang.c Subject: Re: how do I exec() a script Message-ID: <717@scaxs2.pkinbg.uucp> Date: 28 Jun 90 09:43:58 GMT References: <661@kps.UUCP> Sender: caxwgk@pkinbg.uucp Lines: 24 From article <661@kps.UUCP>, by llj@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