1
我有一個.net應用程序需要產生一個控制檯進程(一個java應用程序)並捕獲輸出以便以各種方式對其進行響應。捕獲進程的所有控制檯
我沒有太多的麻煩,導致進程產生,並獲得最多的輸出,但其中一些缺失。我假設它不會「標準輸出」,但我需要找出如何捕捉它。
Public Sub Start()
Dim cmdArgs As String
cmdArgs = "-jar """ & Config.ServerJar & """"
'' Configure the main server process
mServerProcess = New Process
With mServerProcess.StartInfo
.WorkingDirectory = Config.WorkingDirectory
.FileName = Config.Java
.Arguments = cmdArgs
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardError = True
.RedirectStandardInput = True
.RedirectStandardOutput = True
End With
'' Wire up an event handler to catch messages out of the process
AddHandler mServerProcess.OutputDataReceived, AddressOf OutputHandler
AddHandler mServerProcess.ErrorDataReceived, AddressOf ErrorHandler
'' Start the server process
mServerRunning = False
mServerProcess.Start()
'' Wire up the writer to send messages to the process
Dim ioWriter As IO.StreamWriter = mServerProcess.StandardInput
ioWriter.AutoFlush = True
'' Start listening for output
mServerProcess.BeginOutputReadLine()
'' Sleep for a while to let the server settle
Threading.Thread.Sleep(5000)
'' Send test command to the server
ioWriter.WriteLine("test")
'' Wait for the server to terminate
mServerProcess.WaitForExit()
mServerRunning = False
End Sub
Private Sub OutputHandler(ByVal SendingProcess As Object, _
ByVal OutLine As DataReceivedEventArgs)
If Not OutLine.Data Is Nothing Then
Debug.Print("STD:" & OutLine.Data)
End If
End Sub
所以,我的問題是,怎樣才能我要麼所有控制檯輸出?