C-Execute-Command
Conor P. Cahill
cpcahil at virtech.uucp
Sun Dec 3 03:12:37 AEST 1989
In article <2615 at servax0.essex.ac.uk>, georg at SunLab13.essex.ac.uk (Georgatos G) writes:
> Does anybody know how to call an executable file from
> a c-program ?
> I am using the Unix-CC copiler.
Look up the word execute in the permuted index for you programmers reference
manual. Therein you will find references to the exec(2) manual page.
If you want to use the simplest interface (but much less efficient and
much more prone to security holes) you can use the system(3) library
call (which for some reason is in the index as "issue a shell command"
when it should be something like "execute commands using the shell" or
some such thing).
All of the following will perform an "ls -l dir". If you use one of the
exec()s you need to use fork() and wait() to run the program as a sub-process.
char *args[10];
execl("/bin/ls","ls","-l","dir",(char *) 0);
execlp("ls","ls","-l","dir",(char *) 0);
args[0] = "ls", args[1] = "-l", args[2] = "dir", args[3] = NULL;
execv("/bin/ls",args);
execvp("ls",args);
execvp(args[0],args);
system("ls -l dir");
--
+-----------------------------------------------------------------------+
| Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 !
| Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 |
+-----------------------------------------------------------------------+
More information about the Comp.lang.c
mailing list