Sending output of command line app to a multiline textbox

I am trying to make a simple ping utility

Page 1 of 1

3 Replies - 15244 Views - Last Post: 03 July 2008 - 02:35 PM Rate Topic: -----

#1 tuxmeister  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 36
  • Joined: 25-June 08

Sending output of command line app to a multiline textbox

Posted 02 July 2008 - 11:01 AM

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:

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,

Is This A Good Question/Topic? 0
  • +

Replies To: Sending output of command line app to a multiline textbox

#2 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Sending output of command line app to a multiline textbox

Posted 02 July 2008 - 12:54 PM

View Posttuxmeister, on 2 Jul, 2008 - 01:01 PM, said:

		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.
Was This Post Helpful? 0
  • +
  • -

#3 tuxmeister  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 36
  • Joined: 25-June 08

Re: Sending output of command line app to a multiline textbox

Posted 02 July 2008 - 02:37 PM

View Postdjkitt, on 2 Jul, 2008 - 12:54 PM, said:

View Posttuxmeister, on 2 Jul, 2008 - 01:01 PM, said:

		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 :P I thought I saw it clear when you mentioned it but now I'm lost again.
Was This Post Helpful? 0
  • +
  • -

#4 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Sending output of command line app to a multiline textbox

Posted 03 July 2008 - 02:35 PM

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


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1