Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



C Programming Faqs: Frequently Asked Questions    (ISBN: 0201845199)


 

 List Price: $34.99
 Our Price: $34.99
 Used Price: $23.64

 Release Date: January, 1996
 Manufacturer: Addison-Wesley Pub Co (Paperback)
 Sales Rank: 81,838

 Author: Steve Summit, Deborah Lafferty









More Info

 Exec() 2002-04-11 19:50:53
 
Category: source:c:runtime
Description: Shows how to run files using the exec() family of functions.
Platform: linux
Author: detour
Viewed: 5427
Rating: 3.4/5 (21 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
exec.c
/* exec.c written by detour@metalshell.com
 *
 * There are several different ways to run a program
 * using exec. If you use exec() be aware that it will
 * not return to your program. All arguments to exec must
 * be terminated with NULL.
 *
 * exec*l*: takes a list of args.
 * exec*p*: uses the environment path to search for the file.
 * exec*e*: passes current environment variables as well as
 *          ones you supply in a pointer.
 * exec*v*: takes the arguments as a pointer.
 *
 * http://www.metalshell.com
 *
 */


#include <stdio.h>
#include <unistd.h>

#define TYPE 0

int main() {
  char *args[] = { "/usr/bin/w", "-h",
                   NULL };
  char *envir[] = { "DUMMY=BEER" };

  switch(TYPE) {
    case 0:
      execl("/usr/bin/w", "/usr/bin/w", "-h", NULL);
    case 1:
      execlp("w", "w", "-h", NULL);
    case 2:
      execv("/usr/bin/w", args);
    case 3:
      execle("/usr/bin/w", "/usr/bin/w", "-h", NULL, envir);
    case 4:
      execvp("w", args);
    case 5:
      execve("/usr/bin/w", args, envir);
  }

  printf("This should never be seen.\n");

  return 0;
}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?