0

I've found this code on how to get the output of the shell:

Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo("ApplicationName.exe", "arguments")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oProcess.StartInfo = oStartInfo
oProcess.Start()

Dim sOutput As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
    sOutput = oStreamReader.ReadToEnd()
End Using
Console.WriteLine(sOutput)

This just reports the output once the command has finished, not in real time.

Is there a way on how to get the output in real time?

1 Answer 1

1

There is an event on processes called OutputDataReceived which you will need to subscribe to.

This can be done using

AddHandler

The following way will demonstrate how this is done:

AddHandler oProcess.OutputDataRecived, AddressOf OutputData

From here it will want the method, which either Visual Studio can generate for you, or you can generate. It will need the following arguements

Object sender, DataRecievedEventArgs e

In an actual method, this will look like this:

Private Sub OutputDataRecieved(sender As Object, e As DataRecievedEventArgs)

In here you can use e.Data to get the current line.

Hope this helps

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Thanks! But I don't know how to implement this. Can you give me idea on where will I put this and that?
Just under where you declare your new process, add the first line, after doing so a squiggly line should be under "OutputData". From there click on quick settings and click create new method, Or you can generate the method manually using the last line of code i provided, and inside there do your Console.WriteLine()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.