I making an application where within a function another application is launched with parameters using Processs.start()
The streams are redirected to a richtextbox which prints everything the console does, whilst the console window is hidden. For the purposes of debugging, the console is visible (and blank).
Here are the snippets of code in question:
Delegate Sub myappthing_boxDelg(myappthing_text As String)
Public myappthing_delegate As myappthing_boxDelg = New myappthing_boxDelg(AddressOf myappthing)
Public Sub myappthing(myappthing_text As String)
richtextbox.Text += myappthing_text & Environment.NewLine
richtextbox.SelectionStart = richtextbox.Text.Length
richtextbox.ScrollToCaret()
richtextbox.Text = richtextbox.Text.Replace("[0m", "")
End Sub
The above is what is used to display what the console says in the richtextbox, as well as removing any formatting errors in the last line.
Public Sub myappthing_procDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
If Me.InvokeRequired = True Then
Me.Invoke(myappthing_delegate, e.Data)
Else
myappthing(e.Data)
End If
End Sub
Below is what I use to end the process, it does not need to be a clean ending so the process is just killed, and handlers removed so it can be relaunched within the same instance of my application.
Public Sub kill_myappthing()
If myappthing_proc_state = True Then
myappthing_proc.Kill()
RemoveHandler myappthing_proc.ErrorDataReceived, AddressOf myappthing_procDataReceived
RemoveHandler myappthing_proc.OutputDataReceived, AddressOf myappthing_procDataReceived
myappthing_proc.CancelErrorRead()
myappthing_proc.CancelOutputRead()
myappthing_proc_state = False
lbl_status.Text = "Status: Stopped"
End If
End Sub
Below is where I think the problem lies.
Private Sub myappthing()
myappthing_proc.StartInfo.FileName = ".\backend\myappthingexecutable"
Dim args As String = "-argument"
myappthing_proc.StartInfo.Arguments = ("args")
myappthing_proc.StartInfo.WorkingDirectory = ".\backend\"
myappthing_proc.StartInfo.RedirectStandardError = True
myappthing_proc.StartInfo.RedirectStandardOutput = True
myappthing_proc.EnableRaisingEvents = True
myappthing_proc.StartInfo.UseShellExecute = False
myappthing_proc.StartInfo.CreateNoWindow = False
Application.DoEvents()
AddHandler myappthing_proc.ErrorDataReceived, AddressOf myappthing_procDataReceived
AddHandler myappthing_proc.OutputDataReceived, AddressOf myappthing_procDataReceived
myappthing_proc.Start()
myappthing_proc.BeginErrorReadLine()
myappthing_proc.BeginOutputReadLine()
myappthing_proc_state = True
End Sub
When i run the application and have these functions run the executable it does not print anything in the console window that pops up or in the richtextbox, however when running the executable using a batch file everything prints in the console window perfectly well. I am at a loss of what to do.
Any help or a point in the right direction would be much appreciated. Thank you!
In the code I've provided, the executable is found and is technically run (its process can be seen in task manager), but its console output is blank and it does not actually do anything. One idea I have is that maybe the executable I'm trying to run is itself spawning a child process/second console window which is the one I am trying to get the output from, but I don't know how to go about redirecting the streams from a process that I myself haven't started.