469,085 Members | 978 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,085 developers. It's quick & easy.

Send Ctrl-C to a dos app

Hi code gurus !

I'm creating a front end for a DOS application using VB .Net. I launch this
DOS app using System.Diagnostics.Process :

myProcess.StartInfo.FileName = "myapp.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.Start()

I want to send a CTRL-C event to the DOS app, since it's the only way to
interrupt it (unfortunately I'm not the author so I can't change this).

I tried to send a CTRL-C event using the "ConsoleCtrlEvent" API, with no
success. I tried both :
GenerateConsoleCtrlEvent(ConsoleCtrlEvent.CTRL_C, 0)

and

GenerateConsoleCtrlEvent(ConsoleCtrlEvent.CTRL_C, myprocess.id)

But none of them seems to work.

So if someone can help me, I'd be very grateful.

Thank you in advance !
F.C
Nov 21 '05 #1
4 3817
On Wed, 27 Oct 2004 14:47:48 +0200, F.C. wrote:
Hi code gurus !

myProcess.StartInfo.RedirectStandardInput = True

I want to send a CTRL-C event to the DOS app, since it's the only way to
interrupt it (unfortunately I'm not the author so I can't change this).


Since you have redirected the standard input, can't you just send a CTRL-C
character into the input stream?

I haven't tried this, but it may work.

Dim myStreamWriter As StreamWriter = myProcess.StandardInput
myStreamWriter.Write(Chr(3))

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #2
Hi Chris,

Thanks a lot for your reply. Unfortunately, I just tested and it didn't
work. I also tried chr(26), which is equivalent to Ctrl-Z (sometimes Unix
apps use this hotkey).

It was a smart suggestion though, but it seems I'm still stuck <:)

Regards
F.C.

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> a écrit dans
le message de news: 17*****************************@40tude.net...
On Wed, 27 Oct 2004 14:47:48 +0200, F.C. wrote:
Hi code gurus !

myProcess.StartInfo.RedirectStandardInput = True

I want to send a CTRL-C event to the DOS app, since it's the only way to
interrupt it (unfortunately I'm not the author so I can't change this).


Since you have redirected the standard input, can't you just send a CTRL-C
character into the input stream?

I haven't tried this, but it may work.

Dim myStreamWriter As StreamWriter = myProcess.StandardInput
myStreamWriter.Write(Chr(3))

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #3
On Wed, 27 Oct 2004 19:06:26 +0200, F.C. wrote:
Thanks a lot for your reply. Unfortunately, I just tested and it didn't
work. I also tried chr(26), which is equivalent to Ctrl-Z (sometimes Unix
apps use this hotkey).


After writing to the stream, did you flush the stream? Perhaps that will
help to make sure all the data gets sent:

myStreamWriter.Flush()

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #4
Hmmm, I just tried this too, but it didn't work either. I'm not sure if the
application reacts to a caracter in its input stream, or to a direct
keypress, but it seems it's the second solution unfortunately.

I was hoping the GenerateConsoleCtrlEvent API would simulate this in a
trickiest manner, but I got no results at all.

Anyways, thanks again for your suggestions :)

Bye
F.C.

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> a écrit dans
le message de news: yd****************************@40tude.net...
On Wed, 27 Oct 2004 19:06:26 +0200, F.C. wrote:
Thanks a lot for your reply. Unfortunately, I just tested and it didn't
work. I also tried chr(26), which is equivalent to Ctrl-Z (sometimes Unix
apps use this hotkey).


After writing to the stream, did you flush the stream? Perhaps that will
help to make sure all the data gets sent:

myStreamWriter.Flush()

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by jas | last post: by
2 posts views Thread by Gary | last post: by
3 posts views Thread by Str Noetika | last post: by
reply views Thread by B Loggins | last post: by
3 posts views Thread by William Stacey [MVP] | last post: by
3 posts views Thread by zlf | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.