How to get Output of a Command Prompt Window line by line in Visual Basic?

前端 未结 2 1269
花落未央
花落未央 2020-12-20 00:07

I am trying to get a command line output line by line till the end of the output but I am not able to do so. I am using it in my Form and this code executes on click of a bu

2条回答
  •  醉酒成梦
    2020-12-20 00:34

    I've done some research. adb help writes output into STDERR. So you need something like:

        Dim proc As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
        Dim pr As Process
        proc.CreateNoWindow = True
        proc.UseShellExecute = False
        proc.RedirectStandardInput = True
        proc.RedirectStandardOutput = True
        pr = Process.Start(proc)
        pr.StandardInput.WriteLine("C:\sdk\platform-tools")
        pr.StandardInput.WriteLine("adb help 2>&1")
        pr.StandardInput.Close()
        Console.WriteLine(pr.StandardOutput.ReadToEnd())
        pr.StandardOutput.Close()
    

    to catch it.
    You need no 2>&1 if you call ipconfig, for example.

提交回复
热议问题