By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,985 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,985 IT Pros & Developers. It's quick & easy.

Send ctrl-c

P: n/a
How do you send Ctrl-C to a standard input stream? Just sending 03 does not
work.

--
William Stacey [MVP]

Mar 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.
Mar 31 '06 #2

P: n/a
| 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?
Mar 31 '06 #3

P: n/a

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:uj**************@TK2MSFTNGP11.phx.gbl...
| 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/de...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
Mar 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.