Path: utzoo!utgpu!watserv1!watmath!iuvax!mailrus!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: C-Execute-Command Summary: RTFM Message-ID: <1989Dec2.161237.23913@virtech.uucp> Date: 2 Dec 89 16:12:37 GMT References: <2615@servax0.essex.ac.uk> Organization: Virtual Technologies Inc. Lines: 37 In article <2615@servax0.essex.ac.uk>, georg@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 | +-----------------------------------------------------------------------+