나는 박쥐 파일을 실행 중이며 출력을 콘솔 창에 표시하고 있습니다. 지금 당장은 박쥐 파일에 의도적으로 실패했습니다 (박쥐 파일에는 "STARET www.webaddress.com"이 포함되어 있습니다). 잡기와 모든 것이 작동하지만 콘솔 창이 즉시 닫힙니다. 나는 그것을 열어두고 싶습니다만, 지금까지 어떻게 그렇게 할 수 있는지 찾는 것은 어떤 해결책도 찾아 내지 못했습니다.완료 후 콘솔 창을 열어 두십시오.
는 코드 내가 현재 가지고 :
Me.processStartInfo = New ProcessStartInfo("C:\Admin\PsTools\psexec.exe", "\\PCName -u domain\" & user & " -p " & pass & " pathtobatfile")
Me.processStartInfo.RedirectStandardError = True
Me.processStartInfo.RedirectStandardOutput = True
Me.processStartInfo.WindowStyle = ProcessWindowStyle.Hidden
Me.processStartInfo.UseShellExecute = False
Dim process As System.Diagnostics.Process = Nothing
'Start the process, which runs the bat file on the remote server
process = System.Diagnostics.Process.Start(Me.processStartInfo)
AddHandler process.OutputDataReceived, AddressOf OutputHandler
process.BeginOutputReadLine()
process.WaitForExit()
Dim errorresponse As DialogResult
If process.HasExited And process.ExitCode <> 0 Then
errorresponse = MessageBox.Show("There was an error. Exit code: " & process.ExitCode & _
". Do you wish to view the log?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error)
ElseIf process.HasExited And process.ExitCode = 0 Then
MessageBox.Show("The update completed successfully.", "Success", MessageBoxButtons.OK)
End If
If errorresponse = DialogResult.Yes Then
'To fill in later
End If
그리고 이벤트 핸들러 서브 :
Private Shared Sub OutputHandler(ByVal sendingProcess As Object, ByVal output As DataReceivedEventArgs)
Console.WriteLine(output.Data)
End Sub
나는 또한 단지 Readline와 함께 위해 StreamReader와 Console.Writeline를 사용하여 동기 출력 (일을 해봤 ()),하지만 그 중 하나를 작동하지 않았다.
사용 오류 수준을 추가 할 수 있습니다. http://technet.microsoft.com/en-us/library/bb490920.aspx –