Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET read standard output

Tags:

vb.net

From my application I need to run a command and parse the output. I can do this with no problem but I don't want the command to be displayed. I hoped WindowStyle = ProcessWindowStyle.Hidden would work but it doesn't. Take the sample code below for example. It works fine but the command window still visibly opens and closes very quickly and I need it to never show its ugly face. How can I fix this?

Dim myprocess As New Process
Dim lines As String = ""

With myprocess
    .StartInfo.FileName = "C:\Windows\System32\cmd.exe"
    .StartInfo.Arguments = "/c ipconfig"
    .StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    .StartInfo.RedirectStandardOutput = True
    .StartInfo.UseShellExecute = False
    .Start()
End With

lines = myprocess.StandardOutput.ReadToEnd

MsgBox(lines)
like image 294
Jimmy D Avatar asked Aug 19 '26 02:08

Jimmy D


2 Answers

Try setting CreateNoWindow to True too.

If what you are trying to achieve is to find the IP address(es) of the local machine, there are more direct ways of doing it.

like image 152
Aasmund Eldhuset Avatar answered Aug 23 '26 11:08

Aasmund Eldhuset


Include

.StartInfo.CreateNoWindow = True
like image 40
Bala R Avatar answered Aug 23 '26 11:08

Bala R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!