how do I exec() a script

Cookson cookson at helios.mitre.org
Thu Jun 28 05:19:17 AEST 1990


In article <661 at kps.UUCP> llj at kps.se (Leif Ljung /DP) writes:
>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 only way I have been able to exec the script is by executing
>a one-liner containing  `#! /bin/sh /path/prog.  '
>
>But this is not what I want. Not only is the first line limited in 
>length - 32 chars according to exec(2) - it also requires a secondary 
>file that I do not want, I just want to feed the script itself into 
>/bin/sh using the exec(). Is there a way to do this?
>
Well, I'm not sure if this is what you want,  but I'll give it a try.
If I uderstand the question, you want a 'C' program to be able to
exec.  The file that it exec's can be either an executeable, or
a shell script, and you want to be able to specify just the filename
to be execed, and have exec look it up in the PATH environment
variable.  Yes??  Ok if that is the case, then just do this:

execlp("file_to_be_execed", "file_to_be_execed", (a list of arguments, if
any, separated by commas), (char *) 0);

That should do the trick.

Hope this helps,
Dean


% Dean Cookson				  $ Anyone can be taught to sculpt    %
% dcookson at mitre.org			    $ Michaelangleo would have had to %
% {devax,et al..}!linus!mbunix!helios!cookson $ have been taught how not to.  %
% Disclaimer: My opinions are my own, and       $ The same is true of great   %
%       are of questionable sanity                $ programmers               %



More information about the Comp.lang.c mailing list