1

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.)

Arton
  • 443
  • 1
  • 6
  • 15
  • Hi, if you omit completely the call to BeginOutputReadLine how does it work? You should be able to catch the output anyway because you have set an event handler for OutputDataReceived, so how does it behave? – Davide Piras Feb 23 '11 at 16:17
  • I have the related function dealing with that and just pasted them here. I can use backgroundworker and get the output of test.exe, but I don't know how to get "all" of the output of test.exe containing \n and \r. – Arton Feb 24 '11 at 05:48

1 Answers1

1

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.

Community
  • 1
  • 1
bug-a-lot
  • 2,446
  • 1
  • 22
  • 27