从 CMD 响应 c# 获取单行并将其放入文本框
Getting single line from CMD response c# and put it into textbox
所以我想通过 cmd window 获得 adb devices
的响应,然后显示在文本框中。
此时此刻我有这段代码:
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "";
process = Process.Start(startInfo);
**process.StandardInput.WriteLine("adb devices");
connected_devices.Text = process.StandardOutput.ReadLine();
此刻我得到以下结果:
Microsoft Windows [Version 6.1.7601]
而不是只是:
list of attached devices
xxxxxxxx device
感谢任何帮助。
使用StandardOutput.ReadToEnd()。
所以感谢以上post这是我的解决方案
startInfo.FileName = "adb.exe";
startInfo.Arguments = "devices";
process = Process.Start(startInfo);
connected_devices.Text = process.StandardOutput.ReadToEnd();
并打印出来:
List of devices attached
xxxxxxx device
这就是我想要的
所以我想通过 cmd window 获得 adb devices
的响应,然后显示在文本框中。
此时此刻我有这段代码:
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "";
process = Process.Start(startInfo);
**process.StandardInput.WriteLine("adb devices");
connected_devices.Text = process.StandardOutput.ReadLine();
此刻我得到以下结果:
Microsoft Windows [Version 6.1.7601]
而不是只是:
list of attached devices
xxxxxxxx device
感谢任何帮助。
使用StandardOutput.ReadToEnd()。
所以感谢以上post这是我的解决方案
startInfo.FileName = "adb.exe";
startInfo.Arguments = "devices";
process = Process.Start(startInfo);
connected_devices.Text = process.StandardOutput.ReadToEnd();
并打印出来:
List of devices attached
xxxxxxx device
这就是我想要的