Bonjour,
J'essaye de récupérer le résultat d'une fenêtre ms dos dans un simple textbox.
Cela fonctionne mais pas en temps réel.

L'output de ms dos est bien redirigé vers le textbox.
Si le résultat d'un ping par exemple met 6 secondes en dos. Je dois attendre 6 secondes pour voir apparaître l'entièreté sur le textbox. J'aimerais bien que tout soit synchronisé en temps réel.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    Sub _command_netsh(ByVal _context As String, ByVal _command As String, ByVal _argument_1 As String, ByVal text_box_name As TextBox)
        Dim _command_string_builder As New StringBuilder(_context & _command & Chr(34) & _argument_1 & Chr(34))
        Dim my_network_process As New Process()
        my_network_process.EnableRaisingEvents = True
        With my_network_process.StartInfo
            .Arguments = _command_string_builder.ToString()
            .FileName = "netsh.exe" '"hypertrm.exe" '"tracert.exe"
            .UseShellExecute = False
            .CreateNoWindow = True
            .RedirectStandardOutput = True
            .StandardOutputEncoding = Encoding.GetEncoding(863) '(850) '("iso-8859-1")
        End With
 
 
        AddHandler my_network_process.OutputDataReceived, AddressOf p_OutputDataReceived
 
        my_network_process.Start()
        'text_box_name.Text = my_network_process.StandardOutput.ReadToEnd
        'text_box_name.Text = my_network_process.StandardOutput.ReadLine()
        my_network_process.BeginOutputReadLine()
        my_network_process.WaitForExit()
 
 
    End Sub
 
    Private Sub p_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
        If e.Data IsNot Nothing Then
            TextBox1.Text += (e.Data.ToString) + Chr(13)
        End If
    End Sub
J'ai essayé cette ligne aussi qui n'affiche que le début du ping. Mais ce n'est sûrement pas la solution à mon problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
my_network_process.WaitForExit(2000)
Pour utiliser mon code j'ai dressé une liste de commandes utiles dans un dropdownlist qui s'appelle diag_connectivite et l'output msdos dans textbox1

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
    Protected Sub diag_connectivite_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles diag_connectivite.SelectedIndexChanged
 
        _command_netsh("diag ", diag_connectivite.SelectedValue, "", TextBox1)
 
    End Sub
Vous pouvez remplacer diag_connectivite.SelectedValue par "ping loopback" si vous voulez tester mon code.

Avez-vous des idées pour que mon textbox se remplisse petit à petit ?

PS : Je ne veux pas utiliser l'objet ping reply car je perdrais l'intérêt des commandes que l'on peut passer en MS-DOS

Merci.