Reading Standard Output from a Command Line process without newline

折月煮酒 提交于 2020-01-15 05:49:10

问题


I'm writing a C# GUI Wrapper that wraps around an executable (which I CAN NOT modify because I do not have the source code). The problem I'm facing appears to be related to the fact the executable output does not end with a 'newline' character.

Instead, the .exe starts work and expects user input (s=status, q=quit, etc..).

I've spent a lot of time researching various ways to read StdOut, one with Asynchronous reads and listening for events, and the other method was with separate threads polling StdOut and StdErr and raising events to the UI thread which is updating the textbox.

Unfortunately, neither of these two methods seem to work since in both cases - the process does not raise events until the last line of output (one which has no 'newline' at the end), which is only displayed when the application closes.

Also, I can't seem to be able to send commands to it either by writing to it's StandardInput. I've followed the typical advice of disabling ShellExecute, Redirecting Input, etc...

I tried sending both a string, a char, a hex-representation of a char both as Write() and WriteLine(), and neither of those appear to work.

Any ideas?

来源:https://stackoverflow.com/questions/8625443/reading-standard-output-from-a-command-line-process-without-newline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!