Search code examples
c#winformscmdadbredirectstandardoutput

Getting single line from CMD response c# and put it into textbox


So I want to get the response of adb devices put through a cmd window and then to show up in a text box. At this moment in time I have this code:

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();

At this moment in time I am getting the following results:

Microsoft Windows [Version 6.1.7601]

Rather than just:

list of attached devices
xxxxxxxx       device

any help is appreciated.


Solution

  • Use StandardOutput.ReadToEnd().