Need to send Cntrl +C to an Running Exe using a DOS batch File.

Please support our Legacy and Other Languages advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 26
Reputation: programmer321 is an unknown quantity at this point 
Solved Threads: 0
programmer321 programmer321 is offline Offline
Light Poster

Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #1
Jun 20th, 2008
Hello,

I have a query regarding a DOS command. I know this link is not the right place to ask queres about DOS but didnt find any another link in this forum.

I need to send Cntrol +C to a running Exe (running on Windows) using a batch file.Can Any one guide me for this.

Regards.
Last edited by Ancient Dragon; Jun 20th, 2008 at 8:21 am. Reason: deleted inappropriate use of code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,448
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #2
Jun 20th, 2008
>>Can Any one guide me for this.
As a batch file, forget it. Can't be done. There is no way to send anything to an already running program from a batch file. But you can write a C or C++ program to do that and call that program from the batch file.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 26
Reputation: programmer321 is an unknown quantity at this point 
Solved Threads: 0
programmer321 programmer321 is offline Offline
Light Poster

Re: Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #3
Jun 24th, 2008
But this thing is definitely possible in Linux.
Last edited by Ancient Dragon; Jun 24th, 2008 at 8:35 am. Reason: removed mis-used code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,448
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #4
Jun 24th, 2008
Shell programming in *nix is considerably more powerful than batch processing in MS-DOS and MS-Windows. Most things you see in *nix shell programs are not possible in batch files.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #5
Jul 3rd, 2008
Ancient Dragon is correct, there is no way of manipulating threads using batch - or in other words, there is no command redirection available under command.com which allows you to send command output from a control-c into the input thread of a running program. You would have to use a programming language with a WIndows API available so you can manipulate threads via the Kernel.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: Need to send Cntrl +C to an Running Exe using a DOS batch File.

 
0
  #6
Sep 3rd, 2008
All the other posters are correct from what I can tell. If you want to access a thread of a process your out of luck unless you bust out some C/C++ code to terminate it. If you just want to kill the running process then you can try to use pskill.exe provided in the Systernals Tools. Here is the help from the tool:

PsKill v1.12 - Terminates processes on local or remote systems
Copyright (C) 1999-2005 Mark Russinovich
Sysinternals - www.sysinternals.com

Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
-t Kill the process and its descendants.
-u Specifies optional user name for login to
remote computer.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
Not necessarily a Ctrl+C, but it is a way to stop a process that is not owned/created by the batch file. Of course, if you are trying to send a SIGINT or SIGHUP you won't get the expected results using the above method.
Last edited by mittelgeek; Sep 3rd, 2008 at 9:21 am. Reason: Spelling errors
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Legacy and Other Languages Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC