Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

Send Ctrl-C to a dos app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
F.C. - 27 Oct 2004 13:47 GMT
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
Chris Dunaway - 27 Oct 2004 14:25 GMT
> 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))

Signature

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.C. - 27 Oct 2004 18:06 GMT
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.

>> Hi code gurus !
>>
[quoted text clipped - 10 lines]
> Dim myStreamWriter As StreamWriter = myProcess.StandardInput
> myStreamWriter.Write(Chr(3))
Chris Dunaway - 27 Oct 2004 19:05 GMT
> 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()

Signature

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.C. - 27 Oct 2004 22:54 GMT
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.

>> 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
[quoted text clipped - 4 lines]
>
> myStreamWriter.Flush()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.