Lancer commande dos / process

Résolu
plop3000 Messages postés 135 Date d'inscription mercredi 23 mai 2007 Statut Membre Dernière intervention 7 avril 2012 - 19 juin 2007 à 11:42
plop3000 Messages postés 135 Date d'inscription mercredi 23 mai 2007 Statut Membre Dernière intervention 7 avril 2012 - 19 juin 2007 à 12:14
Bonjour,

j'essaye de lancer une commande dos via un process mais je n'y parviens pas dans tout les cas.
Par exemple, j'ai fait :    System.Diagnostics.

Process proc =
new
System.Diagnostics.
Process();proc.EnableRaisingEvents false;proc.StartInfo.FileName

"net";proc.StartInfo.Arguments =

"start "monService"";proc.Start();

et là ça fonctionne. Par contre, je voudrais aussi faire un "cd qqchose" puis un "installutil monService.exe" mais ça ne marche pas. J'ai fais le code suivant mais il ne fonctionne pas :

//Récupération du chemin courant

String strFilePath1 =
AppDomain.CurrentDomain.BaseDirectory;System.Diagnostics.

Process proc1 =
new System.Diagnostics.Process();proc1.EnableRaisingEvents false;proc1.EnableRaisingEvents
false;proc1.StartInfo.FileName "cd ";proc1.StartInfo.Arguments strFilePath1;

proc1.Start();
proc1.StartInfo.FileName "installutil";proc1.StartInfo.Arguments

"monService.exe";proc1.Start();

Si vous avez une solution, je suis preneur...

Merci d'avance

2 réponses

cs_niky Messages postés 168 Date d'inscription jeudi 28 juin 2001 Statut Membre Dernière intervention 18 octobre 2008 7
19 juin 2007 à 11:49
C'est normal que ça ne fonctionne pas. Quand tu lances un process, le répertoire courant dans lequel il se lance est le répertoire courant de ton application. Quant tu lances ton deuxième process, la commande "cd" est terminée et c'est comme si tu ouvrais une nouvelle console.

Tu peux utiliser la propriété WorkingDirectory pour lancer installutil à partir du répertoire strFilePath1.
3
plop3000 Messages postés 135 Date d'inscription mercredi 23 mai 2007 Statut Membre Dernière intervention 7 avril 2012 1
19 juin 2007 à 12:14
Merci Niky, ça marche, tu as raison. Voici le code modifié si ça intéresse quelqu'un :
//Récupération du chemin courant

String strFilePath =
AppDomain.CurrentDomain.BaseDirectory;System.Diagnostics.

Process proc =
new System.Diagnostics.Process();proc.EnableRaisingEvents false;proc.StartInfo.WorkingDirectory strFilePath;
proc.StartInfo.FileName "installutil";proc.StartInfo.Arguments

"monService.exe";proc.Start();
3
Rejoignez-nous