我正在编写一个应用程序来管理其他控制台应用程序(游戏服务器 - jampded.exe
)
当它在控制台中运行时,它会毫无问题地写入数据并读取命令。
在我的应用程序中,我将标准 I/O 重定向到 StreamWriter 和 StreamReader
Public out As StreamReader
Public input As StreamWriter
Dim p As New Process()
p.StartInfo.FileName = My.Application.Info.DirectoryPath & "\" &
TextBox6.Text 'PATH TO JAMPDED.EXE
p.StartInfo.Arguments = TextBox1.Text 'EXTRA PARAMETERS
p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.UseShellExecute = False
p.Start()
input = p.StandardInput
out = p.StandardOutput
Dim thr As Thread = New Thread(AddressOf updatetextbox)
thr.IsBackground = True
thr.Start()
Sub updatetextbox()
While True
While Not out.EndOfStream
RichTextBox1.AppendText(out.ReadLine())
RichTextBox1.AppendText(vbNewLine)
End While
End While
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) _
Handles Button2.Click
input.WriteLine(TextBox4.Text)
TextBox4.Text = ""
input.Flush()
End Sub
当我按下Button2
应该从我的文本框中写入 STD/I 文本时,jampded.exe
就像它没有被写入一样。输出在启动时也能很好地工作,之后当缓冲区中有大量数据时很少添加新行。
我做错了什么,还是应用程序的错?