Visualizza versione completa : [C/C++] Eseguire un file
UG0_BOSS
07-06-2006, 00.42.23
Come da titolo
C'è un modo per lanciare un programma "esterno" da un programma in C o C++ in modo da poter creare una specie di batch in C?
boyashi
07-06-2006, 02.01.03
Devi usare una API di windows "CreateProcess", ecco un esempio:
#include <windows.h>
#include <stdio.h>
void main( VOID )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
"\"C:\\Program Files\\MyApp.exe\" -L -S", // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return;
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
Semi.genius
07-06-2006, 09.58.15
Originariamente inviato da UG0_BOSS
Come da titolo
C'è un modo per lanciare un programma "esterno" da un programma in C o C++ in modo da poter creare una specie di batch in C?
Se non hai troppe pretese puoi fare così
#include <stdlib.h>
void main(){
System("Percorso file da eseguire");
}
System invoca il percorso scelto...stai attento che se ha delle "\", le devi raddoppiare perché il compilatore potrebbe interpretarli come caratteri speciali
UG0_BOSS
07-06-2006, 16.36.03
(Y) grazie... credo che sceglierò la seconda soluzione, mi sembra più semplice :) ciao!!!
vBulletin® v3.8.6, Copyright ©2000-2025, Jelsoft Enterprises Ltd.