The code below is unable to exit and hang the application. After pxx_gen.exe is executed, it will request the user to input 8-digit number then it complete. I'm trying to fix it but still no help, don't know what went wrong.
Dim SerNum_Path As String = "C:\Honey\plx_gen.exe"
Private Sub btnProgram_SerNum_Click(sender As Object, e As EventArgs) Handles btnProgram_SerNum.Click
Dim reader As StreamReader
Dim outline As String
Dim failflag As String = Nothing
lblProgramming_Status.Text = String.Empty
lblProgramming_Status.Text = "Generate..."
reader = Program_the_Number("cmd.exe", "plx_gen.exe", SerNum_Path, tbxNumber.Text.Trim)
While Not reader.EndOfStream
outline = reader.ReadLine()
rtbProgramming_Console.AppendText(outline & vbCrLf)
Console.WriteLine(outline)
If outline.Length > 8 Then
If outline.IndexOf("file open hb_b0_sn.bin") <> -1 Then
failflag = reader.ReadLine()
rtbProgramming_Console.AppendText(failflag & vbCrLf)
End If
End If
End While
If failflag <> ("file open hb_b0_sn_new.bin") Then
lblProgramming_Status.Text = String.Empty
lblProgramming_Status.Text = "Fail"
Return
End If
lblProgramming_Status.Text = String.Empty
lblProgramming_Status.Text = "Generate Done"
End Sub
Public Function Program_the_Number(ByVal programName As String, ByVal cmdString As String, ByVal programPath As String, ByVal SNumber As String) As StreamReader
Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process() proc.StartInfo.CreateNoWindow = True
proc.StartInfo.FileName = programName
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardError = True
proc.StartInfo.RedirectStandardInput = True
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
If programPath.Length > 17 Then
proc.StandardInput.WriteLine(programPath(0).ToString() & ":")
If cmdString.Length <> 0 Then
proc.StandardInput.WriteLine("cd " & programPath.Substring(0, (programPath.Length - 17))) End If
End If
proc.StandardInput.WriteLine(cmdString)
proc.StandardInput.WriteLine(SNumber)
proc.StandardInput.WriteLine("exit")
Dim reader As StreamReader = proc.StandardOutput
proc.Close()
Return reader
End Function