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 88 89
| 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;
HANDLE fd1;
HANDLE fd2;
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 = CreateFile (fichier_entree, NULL, NULL, PEN_ALWAYS, NULL, NULL);
DuplicateHandle (fd1, NULL, ENTREE_STANDARD, NULL, NULL, NULL, NULL);
}
CloseHandle (num_pipe[LECTURE]);
DuplicateHandle (num_pipe[ECRITURE], NULL, SORTIE_STANDARD, NULL, NULL, NULL, NULL);
_spawnvp (_P_WAIT, commandes[PREMIERE_COMMANDE][0], commandes[0]);
}
else
{
if (position_fichier_sortie)
{
fd2 = CreateFile (fichier_sortie, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, PEN_ALWAYS, NULL, NULL);
DuplicateHandle (fd2, NULL, SORTIE_STANDARD, NULL, NULL, NULL, NULL);
}
CloseHandle (num_pipe[ECRITURE]);
DuplicateHandle (num_pipe[LECTURE], NULL, ENTREE_STANDARD, NULL, NULL, NULL, NULL);
_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 = CreateFile (fichier_entree, NULL, NULL, PEN_ALWAYS, NULL, NULL);
DuplicateHandle (fd1, NULL, ENTREE_STANDARD, NULL, NULL, NULL, NULL);
}
if (position_fichier_sortie)
{
fd2 = CreateFile (fichier_sortie, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, PEN_ALWAYS, NULL, NULL);
DuplicateHandle (fd2, NULL, SORTIE_STANDARD, NULL, NULL, NULL, NULL);
}
_spawnvp (commandes[PREMIERE_COMMANDE][0], commandes[PREMIERE_COMMANDE]);
}
}
}
else
{
printf ("probleme de processus numero 1");
}
} |
Partager