Bonjour,
Alors je voudrai afficher le résultat d'une commande système ( cmd /k ipconfig /all ) qui permet de visualiser la configuration IP dans une textbox ou autre.
Comment procéder?
Merci :ccool:
Version imprimable
Bonjour,
Alors je voudrai afficher le résultat d'une commande système ( cmd /k ipconfig /all ) qui permet de visualiser la configuration IP dans une textbox ou autre.
Comment procéder?
Merci :ccool:
Salut,
il faut utiliser la classe Process dans laquelle tu vas rediriger les sorties de la commande. Ce lien peut t'aider.
Voila le code mon processus s'arrete à myProcess.Start();
code:
Code:
1
2
3
4
5
6
7
8
9
10
11
12 Process myProcess = new Process(); ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd/k ipconfig/all"); myProcessStartInfo.UseShellExecute = false; myProcessStartInfo.RedirectStandardOutput = true; myProcess.StartInfo = myProcessStartInfo; myProcess.Start(); StreamReader myStreamReader = myProcess.StandardOutput; // Read the standard output of the spawned process. string myString = myStreamReader.ReadLine(); richTextBox1.Text=myString; myProcess.Close();
il ne faut pas passer toutes la chaîne "cmd/k ipconfig/all". il y a pour cela des arguments dans Argumeents (lien)
:faq:
http://dotnet.developpez.com/faq/csh...yst_procstdout
Au fait, inutile d'appeler "cmd /k ipconfig /all", tu peux appeler directement "ipconfig /all"
"cmd/k ipconfig/all" donne quoi alors je ne vois pas?
Merci beaucoup pour votre aide:ccool:
Ou plus simplement :Code:ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("cmd ", "/k ipconfig /all");
Code:ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("ipconfig ", "/all");
oui c'est ce que j'avais essayé mais j'ai cela dans mon textbox:Citation:
Microsoft Windows [version 6.1.7600]
peut-être parce que ta TextBox n'est pas MultiLine, donc ça n'affiche que la première ligne...
J'utilise une richtextbox ca devrait m'afficher toutes les lignes?
Code:string myString = myStreamReader.ReadLine();
voila ou était l'erreur :mrgreen:
Merci pour tous :ccool:
Par contre j'ai un autre problème pour la commande ping -n 1 127.0.0.1
ca me retourne:(au lieu de me retourner le test?!!)
Citation:
Microsoft Windows [version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Tous droits r‚serv‚s.
C:\Users\cyril\Desktop\Test Ethernet\WindowsFormsApplication7\bin\Debug>
mon code:
Je ne comprend pas trop :(Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 { // Redirection de la commande ping sur l'adresse de boucle dans la richtextbox Process mProcess = new Process(); ProcessStartInfo mProcessStartInfo = new ProcessStartInfo("cmd", "ping -n 1 127.0.0.1"); mProcessStartInfo.UseShellExecute = false; mProcessStartInfo.RedirectStandardOutput = true; mProcess.StartInfo = mProcessStartInfo; mProcess.Start(); StreamReader mStreamReader = mProcess.StandardOutput; string mString = mStreamReader.ReadToEnd(); richTextBox1.Text = mString; mProcess.Close(); }
Mais pourquoi tu insistes pour utiliser cmd ? ça ne sert à rien, à part à foutre le boxon dans le texte en sortie... Appelle directement ping :
Mais là encore, ça ne sert à rien : il existe une classe Ping qui sert à çaCode:ProcessStartInfo mProcessStartInfo = new ProcessStartInfo("ping", "-n 1 127.0.0.1");
Merci :ccool: