previous | start | next

Exec and Command Line Arguments 02

(source)
    1   /*------------------------------------------------------------------------
    2   | 
    3   |       File: exec03.c
    4   | 
    5   |       Description: Calls execlp to execute printArgs
    6   |       with "command line arguments", but so that
    7   |       printArgs gets the same arguments that it would
    8   |       if run by a shell.
    9   |       
   10   |       Created:  8 Jan 15
   11   |       Author: glancast
   12   | 
   13   +-----------------------------------------------------------------------*/
   14   
   15   
   16   #include <stdio.h>
   17   #include <stdlib.h>
   18   #include <unistd.h>
   19   
   20   int main(int argc, char *argv[])
   21   {
   22     execlp("printArgs", "A", "B", "C", (char *) 0);
   23     printf("execlp failed!\n");
   24     return 0;
   25   }

Output: (Same as runing printArgs from the command prompt.)
argv[0] = 'printArgs'
argv[1] = 'A'
argv[2] = 'B'
argv[3] = 'C'


previous | start | next