C# controlling a console process
I'm currently working on a program which has to compile a simple c++ program, run it, input something and write the output. So lets say we have a simple C++ source code. My program woult take the file, compile it, run the resulting exe file, input the values saved in an array, one at a time, and write the resulting output to a label or text area.
Ok, I already managed to write an aplication that would use a default compiler to compile the program, test if there were any errors, warnings, if the exe file was made.
I started the program as a Process, I also managed to redirect the standard output,input.
Now the 开发者_如何学Gobiggest problem is how to figure out when the process is demanding user input.
Is there any way to control the process, like checking when the program is demanding user input, dynamically writing everything the process spits out,... ?
I already attached a DataReceivedEventHandler to my process, but it's acting a little funny. I think it doesn't trigger until my process outputs a whole line. But I would honestly rather see that every character is written emediately. Espetially cause it can happen that the console program outputs "Press any key to continue..." and this is not a whole line until I don't press any key (input something).
And about checking if my process demands user input: I can't use patterns in the output to determine if I need to output something. I will have to compile and run many files and the output won't be exactly the same.
So, is there a way to completely take over controll of a process?
Any answer would be apretiated, thx.
if you know all the inputs to start with why dont you supply them all and let the newly compiled exe use it.
精彩评论