Send ctrl-c

  • Thread starter Thread starter William Stacey [MVP]
  • Start date Start date
W

William Stacey [MVP]

How do you send Ctrl-C to a standard input stream? Just sending 03 does not
work.
 
William Stacey said:
How do you send Ctrl-C to a standard input stream? Just sending 03 does
not
work.

Yes it does but that isn't what you mean is it.

What you mean is how can you send an interrupt over a stream and that can't
be done. Ctrl-C is only magic if some code somewhere decides to make it so
and that code is not in any framework I/O class.

What happens normally depends on the app type but basically the app NEVER
receives a CTRL-C on ANY stream.

If your app is a forms app then ctrl-c is just another key event and there
is no standard input stream connected to the keyboard in any way.

If your app is a console app the console receives the key events and sends
them to your stdin but when it sees ctrl-c it interrupts your app instead.
 
| If your app is a console app the console receives the key events and sends
| them to your stdin but when it sees ctrl-c it interrupts your app instead.

Thanks Nick. That makes sense. But the case of cmd.exe, for example,
cntrl-c at the c:\ prompt will just bring you to another prompt and not
close down cmd.exe. And if you do dir /s and do a ctrl-c, it interupts the
dir internal command, so it seems as if console is passing something to
cmd.exe, not just killing the process. What am I missing?
 
William Stacey said:
| If your app is a console app the console receives the key events and
sends
| them to your stdin but when it sees ctrl-c it interrupts your app
instead.

Thanks Nick. That makes sense. But the case of cmd.exe, for example,
cntrl-c at the c:\ prompt will just bring you to another prompt and not
close down cmd.exe. And if you do dir /s and do a ctrl-c, it interupts
the
dir internal command, so it seems as if console is passing something to
cmd.exe, not just killing the process. What am I missing?

You can "catch" (not C# catch) the interrupt and ignore it or pass it on or
whatever - this is what cmd.exe does.

This is one of those cases where having come from C,C++ or UNIX helps.

see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/HTML/_crt_signal.asp
and SIGINT

I do not know the Windows call to send a signal because my C++ is from UNIX
where it is the kill(pid,signal) method which doesn't seem to exist in
windows but I'm sure that there is an equivalent
 

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

Back
Top