Yorkshireman2
Programmer
I am trying to use process.start to run a c program and direct the output to a textbox (in vb.net vs2008) but the program does not seem to run at all.
I used shellexecute in vb6 to run the same c program and I used a method involving createPipe etc. to show the output in a textbox successfully (albeit it only printed the output when the program finished)
In troubleshooting, I can paste the same file path into a run box or cmd prompt and it runs correctly.
I have tried about 6 different ideas from various google searches, including one from a Microsoft man- it still doesn't produce any output. All I see in the textbox is my text that I set into the textbox saying I am starting the file and then immediately I see the text which I set at the end where I print that I have finished; nothing comes from the program.
When I added a boolean flag to indicate if the process had started and stepped past the process.start line, the flag did turn True but the code waited at pProcess.WaitForExit.
The program definitely is NOT running because it should create two text files when it runs but it is not doing this.
This is the latest code I am trying- others say the idea works for them- strange, eh?
What am I missing??
I used shellexecute in vb6 to run the same c program and I used a method involving createPipe etc. to show the output in a textbox successfully (albeit it only printed the output when the program finished)
In troubleshooting, I can paste the same file path into a run box or cmd prompt and it runs correctly.
I have tried about 6 different ideas from various google searches, including one from a Microsoft man- it still doesn't produce any output. All I see in the textbox is my text that I set into the textbox saying I am starting the file and then immediately I see the text which I set at the end where I print that I have finished; nothing comes from the program.
When I added a boolean flag to indicate if the process had started and stepped past the process.start line, the flag did turn True but the code waited at pProcess.WaitForExit.
The program definitely is NOT running because it should create two text files when it runs but it is not doing this.
This is the latest code I am trying- others say the idea works for them- strange, eh?
Code:
Using pProcess As New Process
AddHandler pProcess.OutputDataReceived, AddressOf process_OutputDataReceived
' now can call the c program to deliver the output to the textbox
pProcess.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory() & _
"ReadFields\ReadFieldsInfo.exe"
pProcess.StartInfo.UseShellExecute = False
pProcess.StartInfo.CreateNoWindow = True
pProcess.StartInfo.RedirectStandardInput = True
pProcess.StartInfo.RedirectStandardOutput = True
pProcess.StartInfo.RedirectStandardError = True
Try
Dim pblnStarted As Boolean = pProcess.Start()
pProcess.BeginOutputReadLine()
pProcess.WaitForExit()
Catch ex As Exception
MsgBox("error" & ex.Message)
Finally
pProcess.Close()
End Try
End Using
txtOutput.AppendText(vbNewLine & "Finished Reading Fields")
' try to set cursor to bottom so it scrolls down to last line
txtOutput.SelectionStart = txtOutput.Text.Length
cmdReadFields.Enabled = False
End Sub
Public Sub process_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
UpdateTextBox(e.Data)
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub UpdateTextBox(ByVal text As String)
If txtOutput.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf UpdateTextBox)
Me.Invoke(d, New Object() {text})
Else
txtOutput.AppendText(vbNewLine & text)
End If
End Sub
What am I missing??