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
所以,我的问题是,怎样才能我要么所有控制台输出?