[英]Can't get java version using process standard output (VB.NET)
I need to get java version, so i need java process with parameter "-version" 我需要获取Java版本,所以我需要带有参数“ -version”的Java进程
it works on cmd, and not work on this code. 它适用于cmd,不适用于此代码。 and, it create java process well.
并且,它很好地创建了Java进程。 but i can't get output.
但我无法输出。
What i need to solve this problem? 我需要解决什么问题?
Dim JavaProc As New Process()
Dim JavaProcInfo As New ProcessStartInfo("java", "-version")
With JavaProcInfo
.UseShellExecute = False
.RedirectStandardOutput = True
End With
With JavaProc
.StartInfo = JavaProcInfo
.Start()
End With
Dim sOutput As String
Using sReader As System.IO.StreamReader = JavaProc.StandardOutput
sOutput = sReader.ReadToEnd()
End Using
MsgBox(sOutput)
The version is sitting on the StandardError stream. 该版本位于StandardError流中。 Below is the modified code block;
下面是修改后的代码块; notice that the StandardError stream needs to be redirected.
请注意,需要重定向StandardError流。
Dim JavaProc As New Process()
Dim JavaProcInfo As New ProcessStartInfo("java", "-version")
With JavaProcInfo
.UseShellExecute = False
.RedirectStandardError = True
End With
With JavaProc
.StartInfo = JavaProcInfo
.Start()
End With
Dim sOutput As String
Using sReader As System.IO.StreamReader = JavaProc.StandardError
sOutput = sReader.ReadToEnd()
End Using
MsgBox(sOutput)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.