I'm new to coding. I'm cant seem to figure out/find a solution on how to make my code work correctly when I try to execute. I have built a VB form that creates a command string in a TextBox depending on selections made from a variety of form selections. I'm appending text to the textbox per the selections to create said command string. Once the command is finished being built I want to be able to execute the built textbox.text using a button to execute it, and have the output be displayed in a RichTextBox in my form.
added info. Below is the section of code I'm trying to get working. I wasn't sure if I should add the code to the post or not after reading the creating a post section. lets say the text in the textbox1 would be something like.
psexec.exe \PCname c:\program files\mcafee\virusscan enterprise\mcupdate.exe \update \quiet
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
System.Windows.Forms.Application.DoEvents()
Dim myprocess As New Process
Dim startinfo As New ProcessStartInfo("cmd.exe")
startinfo.Arguments = TextBox1.Text
startinfo.UseShellExecute = False
startinfo.RedirectStandardOutput = True
startinfo.CreateNoWindow = True
myprocess.StartInfo = startinfo
myprocess.StartInfo.Arguments = TextBox1.Text
myprocess.Start()
Dim str1 As String = ""
Using MyStreamReader As IO.StreamReader = myprocess.StandardOutput
str1 = str1 & MyStreamReader.ReadToEnd
End Using
RichTextBox1.Text = str1
end sub
Note: Working version is below.
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
System.Windows.Forms.Application.DoEvents()
Dim myprocess As New Process
Dim startinfo As New ProcessStartInfo(TextBox3.Text, TextBox1.Text)
startinfo.UseShellExecute = False
startinfo.RedirectStandardOutput = True
startinfo.CreateNoWindow = True
myprocess.StartInfo = startinfo
myprocess.Start()
Dim str1 As String = ""
Using MyStreamReader As IO.StreamReader = myprocess.StandardOutput
str1 = str1 & MyStreamReader.ReadToEnd
End Using
RichTextBox1.Text = str1
End Sub