I must have looked through hundreds of articles related to the StandardOutput ReadtoEnd halting but none of them seem to answer my specific question.
The scenario I have is that I'm creating a wrapper for a 3rd party console app to be used in my ASP.NET MVC application. I start the process, pass it an input string (which is a dot file in string format) and the app returns a file (pdf in this case).
The file is placed into the stdout (according to the docs) however I don't seem to be able to read the data out.
When I run the console app manually, I receive the file as text in the output window but the program never really "exits". I have to CTRL+C to end the process.
I'm guessing this is why my calls to
process.StandardOutput.ReadToEnd();
Just hang?
Can anyone shed a bit of light into what I'm doing wrong. I'd like to return the file that's received in the output as a byte[]
from my m开发者_开发技巧ethod call.
Thanks and appologies if it seems like this is a duplicate.
There are two problems:
ReadToEnd()
returns a string. That's no good idea, if the data is binaryReadToEnd()
doesn't return, because the program never exits
Because of this, try reading the underlying stream (process.StandardOutput.BaseStream
) with the more low level stream methods like Stream.Read
and detect yourself when the program finished sending its data.
精彩评论