23 lines
1002 B
C
Executable File
23 lines
1002 B
C
Executable File
/***************************************************************/
|
|
/* demo_exec_scan : */
|
|
/* - Reservation de la place max des arguments */
|
|
/* (30 car.), */
|
|
/* - lecture du nom de la commande a executer, */
|
|
/* - lecture d'un param. obligatoire, */
|
|
/* - execution (avec prise en compte de la */
|
|
/* variable PATH). */
|
|
/***************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
int main ()
|
|
{ char *argv[3];
|
|
argv[0] = (char*) malloc(30); argv[1] = (char*)malloc(30);
|
|
printf ("Nom de la commande a executer : "); scanf ("%s", argv[0]);
|
|
printf ("Un argument (obligatoire) : "); scanf ("%s", argv[1]);
|
|
argv[2] = (char*)0;
|
|
execvp (argv[0],argv);
|
|
printf ("\nERREUR : execvp impossible\n");
|
|
}
|