title: How to wait for ADB output in C#?
body: <p>I want to receive information from a <code>device</code> connected in <code>USB</code> via a C# program using <code>ADB</code> commands then flush the output.</p>
  <pre><code>Process process = new Process();
  process.StartInfo.FileName = &quot;adb.exe&quot;;
  process.StartInfo.Arguments = &quot;logcat -d -b main -v raw -s Command:I&quot;; // get data in Log.I() with name == &quot;Command&quot;
  process.StartInfo.UseShellExecute = false;
  process.StartInfo.RedirectStandardInput = true;
  process.StartInfo.RedirectStandardOutput = true;
  process.StartInfo.RedirectStandardError = true;
  process.Start();
  
  string output;
  do {
      process.StandardInput.WriteLine(&quot;logcat -d -b main -v raw -s Command:I&quot;);
      output = process.StandardOutput.ReadToEnd();
  } while (output.Length &lt; 1);
  
  Console.WriteLine(output);
  
  process.StandardInput.WriteLine(&quot;logcat -c&quot;); // flush logcat
  
  process.WaitForExit();
  
  </code></pre>
  <p>Doing that I understand that the program is constantly executing <code>adb logcat -d -b main -v raw -s Command:I</code>, isn't there a way to call a command one time and wait for the output?</p>
  <p>I can do that in windows prompt using :</p>
  <pre><code>adb shell 'logcat -b main -v raw -s UNIQUE_TAG:I | (read -n 1 &amp;&amp; kill -2 $((BASHPID-1)))'
  </code></pre>
  <p>but is this doable in C#?
  Also the output doesn't seem to be flushed</p>