Arton
Arton

Reputation: 453

Use BeginOutputReadLine when the process output newline or return

I used Process() to execute a external file named "test.exe".

The "test.exe" only prints a string. "abc \n \r xyz\n"

My goal is to get the string and turn each byte to corresponding ASCII code.

That is, I expect the outputs in my c# console are as below, 97 98 99 32 10 32 13 32 120 121 122 10

But when I used BeginOutputReadLine to get the output of test.exe, \n and \r were striped.

As a result, I only got 97 98 99 32 32 32 120 121 122

Finally, I don't want to use synchronized ways like Read, ReadLine, and ReadToEnd. Is there any way to get what I want??

Thanks!

Actually, I create a backgroundWorker to deal with external process test.exe I have a proc_DataReceived and backgroundWorker_Build_ProgressChanged...

the related code as below
http://codepad.org/Gmq1XqXb
all code as below
http://codepad.org/k7VpWynu

(I'm new to stackoverflow. I pasted my code in codepad.org before finding out how to format code here.)

Upvotes: 1

Views: 5862

Answers (1)

bug-a-lot
bug-a-lot

Reputation: 2454

If you use BeginOutputReadLine, the string won't contain the "end of line" characters (or some of them).

See Capture output from unrelated process for another way to capture output of another process. This would work better in your case since you can read the stream character by character.

Upvotes: 1

Related Questions