Beispiel #1
0
Datei: ish.c Projekt: Depado/ish
void  commandeExt(char * com, char *suite)
{
pid_t p;
int n, i, bg;
char **V, *pm, *su, *su2;
   /* cas normal : le shell fork un fils et attend sa fin */
   bg = isDerCar(suite,'&');
   if ((p=fork()) < 0) perror(com);
   else { /* gestion des deux processus */
     if (p == 0) { /* fils */
        n = nbMots(suite);
        printf("Il y a %d parametres !!\n", n);
        V = (char **)malloc((n+2)*sizeof(char*)); /* nb de param + nom commande + NULL */
        if (V == (char**)NULL) perror("malloc");
        else {
            V[0] = com;
            su=suite;
            for (i=1; i<n+1; i++) {
                pm = premierMot(su, &su2);
                V[i] = pm;
                su = su2;
            }
            V[i]=NULL;
            /* execution */
            execvp(com, V);
            perror(com);
        }
        exit(1);
     } else { /* le shell */
         if (bg) return;
         waitpid(p, NULL, 0);
     }
   }
}
Beispiel #2
0
int main(){
	
	gets(str);
	printf("\n\n");
	printf( "Il y a %d mots\n\n", nbMots(str));

	return 0;
}