1 2 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 34
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[])
{int i;
//pipe pip;
int p;
int T[2];
char* options = "test";
char* options1 = "-o";
char commande[1024];
char commande1[1024];
printf("Lancement de %s avec pour arguments \n",argv[0]);
for( i = 1; i < argc;++i)
{
sprintf(commande, "cc %s %s %s", options1,options, argv[i]); // formate la commande à donner à system()
printf("%s : commande: %s\n ",argv[i], commande);
system(commande); // balance la commande
p=fork();
if(p==-1)
printf("Erreur\n");
else if (p==0)
{ close( T[0]);
write(T[1],options,10);
close(T[1]);
read(T[0],options,10);
sprintf(commande1, "./%s",options);
system(commande1);
close(T[0]);
}
}
exit(1);
} |
Partager