OutputDataReceived is not equal to the cmd output. Why?

I create the process this way:

Process process = new Process
            StartInfo = new ProcessStartInfo
                FileName = "cmd",
                Arguments = "/C tools\\adb " + serial + command,
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true,
                RedirectStandardError = true,

Then I subscribe to the event:

process.OutputDataReceived += Display;

I append the data to the StringBuilder:


Finally i append the StringBuilder text to a RichTextBox.


The problem is, that the the output I get is not equal to the output i get with cmd.


CMD (correct):

Line 1 text text text text
Line 2 text text text text
Line 3 text text text text

With C# (wrong):

Line 1 text text text text

Line 2 text text text text

Line 3 text text text text

I also get the wrong output, when I execute

adb logcat -d > output.txt

The problem does not occur, if I use StandardOutput.ReadToEnd(), but then I will not get the live output.

I can not find the problem. Can you help me?


Well, finally I found the answer.

The key is, to use shell commands with no pty. Pty mangles the binary output.

Instead of

adb shell ls


adb exec-out ls

More information:

Read binary stdout data from adb shell?


Transferring binary data over ADB shell (ie fast file transfer using tar)