éxécuter un script

rhumsek Messages postés 17 Date d'inscription lundi 3 février 2003 Statut Membre Dernière intervention 5 novembre 2011 - 5 nov. 2011 à 13:38
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 6 nov. 2011 à 13:22
Bonjour,

comment faire appel à un fichier .bat pour qu'il s'exécute dans un programme en C ( Microsoft Visual Studio 2010) ?

rhumsek

1 réponse

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
6 nov. 2011 à 13:22
Bonjour,

Une petite recherche t'aurais rapidement fait trouver des codes dans ce genre là :

#include <windows.h>
#include <stdio.h>

void __stdcall ExecuteBatch(char* lpBatchName)
{
  STARTUPINFO startupInfo;
  PROCESS_INFORMATION processInfo;

  ZeroMemory(&startupInfo, sizeof(startupInfo));
  startupInfo.cb = sizeof(startupInfo);
  startupInfo.dwFlags = STARTF_USESHOWWINDOW;
  startupInfo.wShowWindow = SW_SHOW;

  CreateProcess(NULL, lpBatchName, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInfo);

  WaitForSingleObject(processInfo.hProcess, INFINITE);

  CloseHandle(processInfo.hThread);
  CloseHandle(processInfo.hProcess);
}

int __cdecl main(int argc, char* argv[])
{
  puts("Executing batch...");

  ExecuteBatch("test.bat");

  puts("Batch executed");
  return 0;
}
0
Rejoignez-nous