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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| void interpreter ()
{
PROCESS_INFORMATION processus_info1;
PROCESS_INFORMATION processus_info2;
STARTUPINFO info_demarage1;
STARTUPINFO info_demarage2;
typedef DWORD id1;
typedef DWORD id2;
SECURITY_ATTRIBUTES attributs;
ZeroMemory (&info_demarrage1, sizeof (STARTUPINFO));
ZeroMemory (&info_demarrage2, sizeof (STARTUPINFO));
attributs.nLength = sizeof (SECURITY_ATTRIBUTES);
attributs.bInheritHandle = TRUE;
attributs.lpSecurityDescriptor = NULL;
if (CreateProcess ("nom_executable", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &info_demarrage1, &processus_info1))
{
*id1 = processus_info1.dwProcessId;
if (!(*id1))
{
if (commandes[SECONDE_COMMANDE][0])
{
if (CreatePipe (num_pipe[LECTURE], num_pipe[ecriture], &attributs, 0)
{
if (CreateProcess ("nom_executable", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &info_demarrage2, &processus_info2))
{
*id2 = processus_info2.dwProcessId;
if (*id2)
{
if (position_fichier_entree)
{
fd1 = open (fichier_entree, 0);
dup2 (fd1, ENTREE_STANDARD);
}
close (num_pipe[LECTURE]);
dup2 (num_pipe[ECRITURE], SORTIE_STANDARD);
_spawnvp (_P_WAIT, commandes[PREMIERE_COMMANDE][0], commandes[0]);
}
else
{
if (position_fichier_sortie)
{
fd2 = creat (fichier_sortie, 0644);
dup2 (fd2, SORTIE_STANDARD);
}
close (num_pipe[ECRITURE]);
dup2 (num_pipe[LECTURE], ENTREE_STANDARD);
_spawnvp (_P_WAIT, commandes[1][0], commandes[1];
}
}
else
{
printf ("probleme de precessus numero 2");
}
}
else
{
printf ("probleme de pipe");
}
}
else
{
if (position_fichier_entree)
{
fd1 = open (fichier_entree, 0);
dup2 (fd1, ENTREE_STANDARD);
}
if (position_fichier_sortie)
{
fd2 = open (fichier_sortie, 0644);
dup2 (fd2, SORTIE_STANDARD);
}
_spawnvp (commandes[PREMIERE_COMMANDE][0], commandes[PREMIERE_COMMANDE]);
}
}
}
else
{
printf ("probleme de processus numero 1");
}
} |
Partager