Send Ctrl-C to a dos app

F

F.C.

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
 
C

Chris Dunaway

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.
 
F

F.C.

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 said:
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.
 
C

Chris Dunaway

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.
 
F

F.C.

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 said:
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.
 

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