Exécuter une commande DOS avec arguments

nbouard Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 26 novembre 2004 - 24 nov. 2004 à 15:14
nbouard Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 26 novembre 2004 - 26 nov. 2004 à 16:11
Bonjour,
Je développe actuellement une application sous Visual C++, et j'aimerais lancer une commande MS-DOS de ce type :
"C:\pv.exe -perf -localhost -wave "E:\ex_grammaire" -option sigFormat=PCM16,externalVAD=true,asrServersListenPort=32001 "E:\ex_grammaire\Document1.spk" > C:\toto".
Il n'y a pas de problème avec la commande system( ), mais celle-ci fait apparaître une fenêtre MS-DOS par dessus mon interface graphique, ce que je souhaîterais éviter.
Donc si quelqu'un sait comment ne pas faire apparaître cette fenêtre, ou bien connaît un autre moyen d'exécuter ma commande, je suis preneur...
Merci d'avance!

7 réponses

yserver Messages postés 203 Date d'inscription lundi 2 août 2004 Statut Membre Dernière intervention 8 septembre 2006
24 nov. 2004 à 15:47
ShellExecute devrait te permetre de faire ce que tu souhaite
ca donnerait :
ShellExecute ( NULL , "open" , "C:\\pv.exe" , "-perf -localhost -wave "E:\\ex_grammaire" -option sigFormat=PCM16,externalVAD=true,asrServersListenPort=32001 "E:\\ex_grammaire\\Document1.spk" > C:\\toto" , NULL , SW_HIDE );

Voila la syntaxe (plus d'info sur msdn)

HINSTANCE ShellExecute(

HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
);
0
nbouard Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 26 novembre 2004
24 nov. 2004 à 15:55
Merci, mais j'avais déjà essayé, et mes options ne sont pas prises en compte par ShellExecute : en fait c'est comme s'il faisait seulement C:\pv.exe...
Une autre solution peut-être?
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
24 nov. 2004 à 16:21
0
nbouard Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 26 novembre 2004
24 nov. 2004 à 16:48
Encore merci, mais j'ai le même problème avec CreateProcess, j'exécute le code suivant :

SECURITY_ATTRIBUTES sa;
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;

sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

ZeroMemory(&StartupInfo, sizeof(STARTUPINFO));

StartupInfo.cb = sizeof(STARTUPINFO);
StartupInfo.dwFlags = STARTF_USESTDHANDLES;
StartupInfo.wShowWindow = SW_HIDE;
StartupInfo.hStdOutput = NULL;

CreateProcess(NULL,"C:\\pv.exe -perf -localhost -wave "C:\\ex_grammaire" -option sigFormat=PCM16,externalVAD=true,asrServersListenPort=32001 "C:\\ex_grammaire\\Document1.spk" > C:\\toto",&sa,NULL,TRUE,DETACHED_PROCESS,NULL,NULL,&StartupInfo, &ProcessInfo);

Mes arguments sont ignorés et toto reste vide !!!
Là je sais vraiment plus quoi faire?...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
bebert37 Messages postés 38 Date d'inscription jeudi 17 juillet 2003 Statut Membre Dernière intervention 16 février 2005
24 nov. 2004 à 18:03
moi j'voterai pour un p'tit execve ou execv (c'est compatible PosiX)de derrière les fagots ... mais bon apres c'est comme tu veux.
voila une p'tite doc qui va avec:
http://www.epita.fr/docs/man2/execve.2.html
ou encore
http://mkssoftware.com/docs/man3/execl.3.asp

bon courage
voila...

Ce sont les tonneaux vides et les hommes pleins qui font le plus de bruit
:big)
0
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
24 nov. 2004 à 18:07
Pour rediriger la sortie standard, il faut mettre un handle du fichier "C:\\toto" pour StartupInfo.hStdOutput.
0
nbouard Messages postés 4 Date d'inscription jeudi 9 septembre 2004 Statut Membre Dernière intervention 26 novembre 2004
26 nov. 2004 à 16:11
Merci à tous. J'ai finalement réussi avec Create Process. Désol pour le temps de réponse mais je ne bosse pas tous les jours sur ce projet... Pour ceux que ça intéresse, voici ma solution:
char *commande =
"E:\\pv.exe -perf -localhost "
"-wave "E:\\ex_grammaire"
"-option SigFormat=PCM16,externalVAD=true,asrServersListenPort=32001 ""E:\\ex_grammaire\\Document1.spk"";

char *resultat = "E:\\toto";

char buffer[200];
BOOL statut;
STARTUPINFO startupinfo;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;

memset(&startupinfo,0,sizeof startupinfo);
memset(&pi,0,sizeof pi);

MessageBox(NULL,commande,"message",MB_OK);

startupinfo.cb = sizeof(startupinfo);
startupinfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
startupinfo.wShowWindow = SW_HIDE;
startupinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startupinfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
sa.nLength = sizeof sa;
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
startupinfo.hStdOutput = CreateFile(
resultat,
GENERIC_WRITE,
FILE_SHARE_WRITE,
&sa,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (startupinfo.hStdOutput==INVALID_HANDLE_VALUE){
MessageBox(NULL,"echec CreateFile","message",MB_OK);;
return;
}

statut = CreateProcess(
NULL,commande,
NULL,NULL,
TRUE,0,
NULL,NULL,
&startupinfo,&pi);

if (statut==FALSE){
MessageBox(NULL,"echec CreateProcess","message",MB_OK);;
CloseHandle(startupinfo.hStdOutput);
return;
}

bool stop = false;
while(!stop) {
DWORD waitstatut = WaitForSingleObject(pi.hProcess,INFINITE);
if (waitstatut == WAIT_OBJECT_0){
DWORD exitcode;
statut = GetExitCodeProcess(pi.hProcess,&exitcode);
if (statut!=FALSE) {
if (exitcode != STILL_ACTIVE){
sprintf(buffer,"exit code = %d",exitcode);
MessageBox(NULL,buffer,"message",MB_OK);;
stop = true;
}
}
}
else {
sprintf(buffer,"signal = %08X",waitstatut);
MessageBox(NULL,buffer,"message",MB_OK);;
stop = true;
}

}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(startupinfo.hStdOutput);
0
Rejoignez-nous