I am controlling a console process which has been started like this:
AvrGdb = new Process();
AvrGdb.StartInfo.CreateNoWindow = true;
AvrGdb.StartInfo.UseShellExecute = false;
AvrGdb.StartInfo.FileName = "avr-gdb.exe";
AvrGdb.StartInfo.RedirectStandardOutput = true;
AvrGdb.StartInfo.RedirectStandardInput = true;
AvrGdb.StartInfo.RedirectStandardError = true;
I'm sending short command strings to the 'command line' and receiving data back. However one of the commands that needs to be sent is CTRL+C. This doesn't shut down the process, it sends it on to control a debugger in a separate microcontroller (the process is the 'avr-gdb' debugger for avr micros).
I have tried both StandardInput.Write('\x3')
and StandardInput.Write(char.ConvertFromUtf32(3));
with no success (i.e. there is no reaction from the process I am writing to).
Many other topics on this subject exist but generally the questioner actually wants to end the process with this command, so other ways of doing that are advised.
One reply that I found had this suggestion, which I thought might work (using an imported C++ 'GenerateConsoleCtrlEvent()'):
Process avrgdb = Process.GetProcessesByName("avr-gdb")[0];
GenerateConsoleCtrlEvent(CTRL_C_EVENT, (uint)avrgdb.SessionId);
but it doesn't - apparently the 'SessionId' needs to be that of a 'processGroup' which isn't accessible (or doesn't exist?) in c#, only in C++.
If I knew that rewriting my whole Process interaction in C++ rather than C# would solve this, then I might attempt to do that, but a big learning curve is involved in that approach. Any other ideas please?