Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 109,337 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 1,044 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Sending output of command line app to a multiline textbox

 
Reply to this topicStart new topic

Sending output of command line app to a multiline textbox, I am trying to make a simple ping utility

tuxmeister
post 2 Jul, 2008 - 11:01 AM
Post #1


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 15



Thanked 1 times
My Contributions


I am just testing stuff and I want to make a graphical ping utility. Basicly, I can't get to send the output of the command to the textbox.

This is the code that I have:

CODE

Public Class Ping_util
    Private Sub Ping_util_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
    Private Function Ping_run() As Boolean
        Dim Ping_runProcess As New Process()
        Dim Ping_runStartInfo As New ProcessStartInfo()
        Dim ComputerID As String = Me.ping_what.Text
        Ping_runStartInfo.FileName = "cmd.exe "
        Ping_runStartInfo.UseShellExecute = False
        Ping_runStartInfo.CreateNoWindow = True
        Ping_runStartInfo.Arguments = "/D /c ping " + ComputerID
        Ping_runStartInfo.RedirectStandardOutput = True
        Ping_runProcess.EnableRaisingEvents = True
        Ping_runProcess.StartInfo = Ping_runStartInfo
        Ping_runProcess.Start()
        Dim output As String
        Dim readerStdOut As IO.StreamReader = Ping_runProcess.StandardOutput
        Do While readerStdOut.EndOfStream = False
            output = readerStdOut.ReadLine()
        Loop
        Me.output_text.Text = "This is the result of the ping:" + output
    End Function

    Private Sub Start_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start_btn.Click
        Ping_run()
    End Sub
End Class


Is the "output" way the good way to do it?

Thanks in advance,
User is offlineProfile CardPM

Go to the top of the page


djkitt
post 2 Jul, 2008 - 12:54 PM
Post #2


D.I.C Head

**
Joined: 22 May, 2008
Posts: 119



Thanked 13 times
My Contributions


QUOTE(tuxmeister @ 2 Jul, 2008 - 01:01 PM) *

CODE

        Do While readerStdOut.EndOfStream = False
            output = readerStdOut.ReadLine()
        Loop
        Me.output_text.Text = "This is the result of the ping:" + output



Just a quick observation.

The above loop will only report the result of the final ReadLine in the loop. If you want every line read before an EndOfStream you need to append each line to output.


User is offlineProfile CardPM

Go to the top of the page

tuxmeister
post 2 Jul, 2008 - 02:37 PM
Post #3


New D.I.C Head

*
Joined: 25 Jun, 2008
Posts: 15



Thanked 1 times
My Contributions


QUOTE(djkitt @ 2 Jul, 2008 - 12:54 PM) *

QUOTE(tuxmeister @ 2 Jul, 2008 - 01:01 PM) *

CODE

        Do While readerStdOut.EndOfStream = False
            output = readerStdOut.ReadLine()
        Loop
        Me.output_text.Text = "This is the result of the ping:" + output



Just a quick observation.

The above loop will only report the result of the final ReadLine in the loop. If you want every line read before an EndOfStream you need to append each line to output.


Thanks, nice one and actually pretty obvious. I'm still trying to find my way through all this.

Oh, by the way... how do I do that tongue.gif I thought I saw it clear when you mentioned it but now I'm lost again.
User is offlineProfile CardPM

Go to the top of the page

djkitt
post 3 Jul, 2008 - 02:35 PM
Post #4


D.I.C Head

**
Joined: 22 May, 2008
Posts: 119



Thanked 13 times
My Contributions


To append to a string:
CODE

        Do While readerStdOut.EndOfStream = False
            output = output + readerStdOut.ReadLine()
        Loop
        Me.output_text.Text = "This is the result of the ping:" + output



User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/6/08 04:26PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month