Programación General > C/C++

 Llamar A Un Programa Ejecutable En Windows

(1/1)

pacogonzalez61:
Como desde un programa en  o C++ en Windows puedo llamar a otro programa
ejecutable tambien de Windows . Por ejemplo en MSDOS cuando quiero llamar a
un progrma ejecutables escribo la función system "PROGRAMA.EXE".
Como soy nuevo en c** en Winddow. como puedo hacerlo.
Gracias.

Ruben3d:
Hola.

Lo que pides puedes hacerlo de dos formas: mediante CreateProcess o mediante spawn. Aqui te dejo un ejemplo de cada uno, sacado de MSDN:

Creating a process in Windows using CreateProcess

--- Código: Text --- #include <windows.h>#include <process.h>#include <stdio.h> void main(){    STARTUPINFO    si;    PROCESS_INFORMATION  pi;     GetStartupInfo(&si);     printf("Running Notepad with CreateProcess\n");    CreateProcess(NULL, "notepad",  // Name of app to launch  NULL,      // Default process security attributes  NULL,      // Default thread security attributes  FALSE,      // Don't inherit handles from the parent  0,      // Normal priority  NULL,      // Use the same environment as the parent  NULL,      // Launch in the current directory  &si,      // Startup Information  &pi);      // Process information stored upon return     printf("Done.\n");    exit(0);}  
Creating a process in Windows using spawn

--- Código: Text --- #include <windows.h>#include <process.h>#include <stdio.h> void main(){    printf("Running Notepad with spawnlp\n");    _spawnlp( _P_NOWAIT, "notepad", "notepad", NULL );     printf("Done.\n");    exit(0);}  
Espero que te sirva.

Un saludo.

Ruben3d

Navegación

[0] Índice de Mensajes

Ir a la versión completa