I've been struggling with this all week so I'm hoping the experts here can help me out. I have an executable that absolutely must be run from the command line with arguments. What I'm trying to do is instead of launching the command prompt window, I'd like to send the data to the rich text box on my form.
If I setup a batch file and run the batch file with the correct code (running it as a Process
), this works no problem. However, I'd like for the user to be able to enter their own arguments into a TextBox
instead of creating a batch file and referencing it.
I can only get this application to run correctly by using Call Shell. However, I read that you can't output the data to a RichTextBox
if you're using Call Shell and that it needs to be setup as a new Process
. I just can't seem to get this running as a Process
.
So the question is, is it possible to somehow output the Call Shell data to a RichTextBox
control, or is there a way to get this thing to run as a process? The Visual Basic code below will get it to run, but won't output to the RichTextBox
. I removed any code that I tried because every try was a failure.
This button will start the Process
, or if the Process
is running, it will kill it.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim exeargs As String = txtExeArgs.Text
Dim p1() As Process
Dim strCommand As String = "executable.exe " & exeargs & ""
p1 = Process.GetProcessesByName("executable")
Dim exepath As String = IO.Path.GetDirectoryName(Me.txtExeLocation.Text)
If p1.Count <= 0 Then
RichTextBox1.Clear()
Call Shell("cmd.exe /c cd /d " & exepath & " & " & strCommand, 0)
Else
Dim killprocess = System.Diagnostics.Process.GetProcesses().Where((Function(p) p.ProcessName = "executable"))
For Each p As Process In killprocess
p.Kill()
Next
RichTextBox1.Clear()
End If
End Sub