Cannot send Ctrl-C when wrapping cmd.exe

B

B Loggins

Hi everyone, thanks in advance fo any help on this issue.

I'm trying to "wrap" cmd.exe. That is, I'm redirecting StandardInput
and StandardOutput for a cmd.exe process and I'm sending StdOut to a
RichTextBox where I'm doing stuff to the text. I'm also passing the
characters typed to the RichTextBox to StandardInput for cmd.exe. This
is all working quite well, but the problem is that I cannot get cmd.exe
to process Ctrl-C correctly.

What I want to do is basically emulate the behavior of a user typing
CTRL+C in a cmd.exe window. That is, if there is a long-running batch
file or a child process (like ping.exe or tracert.exe) it will
interrupt the batch file or kill the child process.

Now if I P/Invoke over a SendCtrlEvent it Ctrl-C's cmd.exe itself,
which is not what I want. I basically want to insert the Ctrl+C
character into the input stream and have cmd.exe act as it normally
would. I've played with P/Invoking WriteConsoleInput, SetConsoleMode
(to character at a time mode), ...., all to no avail.

I just can't seem to be able to figure this out and I've searched all
over Usenet and the rest of the net for it. Am I missing something
simple here or am I really in for a lot of work?

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top