| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 
 | #include <stdio.h>
#include <stdlib.h>
  /* pour system et EXIT_SUCCESS */
#include <sys/wait.h>
  /* pour WEXITSTATUS */
 
 
void lance_commande(char *commande) {
 
	int ret;
ret = system(commande);
	switch(WEXITSTATUS(ret)) {
		case -1 :
			perror("Echec de la commande system : ");
			exit(1);
		case  0 : 
			break;
		case  127 : 
			printf("la commande %s n'a pu etre executee\n", commande);
			exit(2);
		default :
			printf("code de retour de %s : %d\n", commande, WEXITSTATUS(ret));
	}
}
 
int main(int argc, char *argv[]) {
 
    int i;
    for (i = 1; i < argc; i++) {
        lance_commande(argv[i]);
    }
    return EXIT_SUCCESS;
} |