我对此不知所措。因此,我只想在VB.net中构建一个使用adb(Android调试桥)的应用程序以获取有关设备的信息。当前,我正在尝试使用命令adb shell getprop ro.product.brand
获取设备的品牌,该命令应返回Amazon
。但是,当我尝试使用if语句查看adb命令的输出是否等于Amazon时,它总是返回错误(指出它不是Amazon设备)。我已经做了很多尝试来使它起作用,但我无法终生解决。有人对如何解决此问题有任何建议吗?我想念什么吗?
Public Class Form1
Function adb(ByVal Arguments As String) As String
Try
Dim My_Process As New Process()
Dim My_Process_Info As New ProcessStartInfo()
My_Process_Info.FileName = "cmd.exe"
My_Process_Info.Arguments = Arguments
My_Process_Info.WorkingDirectory = "adb\"
My_Process_Info.CreateNoWindow = True
My_Process_Info.UseShellExecute = False
My_Process_Info.RedirectStandardOutput = True
My_Process_Info.RedirectStandardError = True
My_Process.EnableRaisingEvents = True
My_Process.StartInfo = My_Process_Info
My_Process.Start()
Dim Process_ErrorOutput As String = My_Process.StandardOutput.ReadToEnd()
Dim Process_StandardOutput As String = My_Process.StandardOutput.ReadToEnd()
Console.WriteLine(Process_ErrorOutput)
Console.WriteLine(Process_StandardOutput)
' Return output by priority
If Process_ErrorOutput IsNot Nothing Then Return Process_ErrorOutput
If Process_StandardOutput IsNot Nothing Then Return Process_StandardOutput
Catch ex As Exception
Return ex.Message
End Try
Return "OK"
End Function
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim BrandofDev
BrandofDev = (adb("/c adb shell getprop ro.product.brand"))
If BrandofDev = "Amazon" Then
MsgBox("This is an amazon device.")
Else
MsgBox("This isn't an Amazon device.")
End If
End Sub
End Class
答案 0 :(得分:1)
我可能错过了重点,但是...
Private Sub OpCode()
'****They are both the same thing so, of course they both print
Dim Process_ErrorOutput As String = My_Process.StandardOutput.ReadToEnd()
Dim Process_StandardOutput As String = My_Process.StandardOutput.ReadToEnd()
Console.WriteLine(Process_ErrorOutput)
Console.WriteLine(Process_StandardOutput)
' Return output by priority
'****The Process_ErrorOutput will always be the one returned
'(but what does it matter; they are both the same) Or Nothing is returned
If Process_ErrorOutput IsNot Nothing Then Return Process_ErrorOutput
If Process_StandardOutput IsNot Nothing Then Return Process_StandardOutput
End Sub
编辑
根据@Jimi的评论
在此处保留.WorkingDirectory
的是相关链接https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.workingdirectory?view=netframework-4.8