2010-10-14 2 views
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 

Итак, мой вопрос, как я могу либо выход всех консоли?

ответ

0

Я идиот.

Я забыл включить вывод ошибки.

mServerProcess.BeginOutputReadLine() 

должен быть

mServerProcess.BeginOutputReadLine() 
    mServerProcess.BeginErrorReadLine()