2017-12-26 31 views
0

이것은 openfiles.exe를 실행하고 출력을 반환합니다. openfiles.exe를 명령 줄에서 실행하면 예상대로 작동합니다. 내가 여기 실행 오류가 없다하지만 난 메시지 박스Openfiles.exe에서 Output을 읽으려고하는데

Dim NewProcess As New Process() 
    With NewProcess.StartInfo 
     .FileName = "openfiles.exe" 
     .Arguments = "/query /s FakeServer/fo csv /V /U FakeDomain\Fakeuser/P pword" 
     .RedirectStandardOutput = True 
     .RedirectStandardError = True 
     .RedirectStandardInput = True 
     .UseShellExecute = False 
     .WindowStyle = ProcessWindowStyle.Normal 
     .CreateNoWindow = False 
    End With 

    NewProcess.Start() 

    System.Threading.Thread.Sleep(5000) 

    MsgBox(NewProcess.StandardOutput.ReadToEnd) 
+0

일부 응용 프로그램 (예 : FFmpeg)은 출력 스트림이 아닌 오류 스트림에 기록합니다. 'MsgBox (NewProcess.StandardError.ReadToEnd())'도 시도해 봤나? –

답변

0

에서 아무 것도 얻을 때 나는 그것이 당신이 뭘 하려는지과 유사해야 그 단지 샘플 코드입니다. 그러나, 내 응용 프로그램 cmd.exe를 사용하여 명령을 실행하고 텍스트 상자에 실시간으로 결과를 표시하려고했습니다. 그에 따라 수정할 수 있습니다.

Dim cmd As New Process() 
Dim strCommandLine As String = "Echo Hello World" 

cmd.StartInfo.FileName = "cmd.exe" 
cmd.StartInfo.RedirectStandardError = True 
cmd.StartInfo.RedirectStandardInput = True 
cmd.StartInfo.RedirectStandardOutput = True 
cmd.StartInfo.CreateNoWindow = True 
cmd.StartInfo.UseShellExecute = False 
cmd.EnableRaisingEvents = True 
Application.DoEvents() 

AddHandler cmd.ErrorDataReceived, AddressOf OutputHandler 
AddHandler cmd.OutputDataReceived, AddressOf OutputHandler 

cmd.Start() 

cmd.StandardInput.WriteLine(strCommandLine) 
cmd.StandardInput.Flush() 
cmd.StandardInput.Close() 
cmd.BeginErrorReadLine() 
cmd.BeginOutputReadLine() 
cmd.Close() 

Delegate Sub UpdateTextBoxDelg(text As String) 
Public myDelegate As UpdateTextBoxDelg = New UpdateTextBoxDelg(AddressOf UpdateTextBox) 

Public Sub UpdateTextBox(text As String) 
    txtOutput.Text += text & Environment.NewLine 
    txtOutput.SelectionStart = txtOutput.Text.Length 
    txtOutput.ScrollToCaret() 
End Sub 

Private Sub OutputHandler(sender As Object, e As DataReceivedEventArgs) 
    If Me.InvokeRequired = True Then 
     Me.Invoke(myDelegate, e.Data) 
    Else 
     UpdateTextBox(e.Data) 
    End If 
End Sub