![]() |
![]() |
|
|||||||
| Register | Forum Rules | Getting Started! - Guide | Blog | Videos | Gallery | Members List | Social Groups | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
![]() |
Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
Hello,
Please help if you could .. I have a simple batch file which runs 2 jobs one after another. Sometime I have to interrupt the job because let say something wrong happened during of execution of my application. In that case I just terminate execution by Control + ^C and answer 'y'. After that I run this command %taskkill.exe ... and kill processes I want to kill. This obviously require additional step after terminating the job. Here is my goal: I want to use this command %taskkill.exe ... in case I terminate batch file and answer 'y' automatically. Could someone please help me with it and explain how to include it in my batch and being called in case of Control ^C? Thanks in advance. |
|
|
|
|
|
#2 |
|
Founder
![]() Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 371
Thanked 411 Times in 356 Posts
Rep Power: 67
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
Well, if you press Ctrl+C or Ctrl+Break the entire script will be aborted. So AFIK we can't include some code to execute after pressing those keys.
A simple solution would be another batch file with the necessary taskkill commands and create a shortcut to it in the quick launch bar for easy access. |
|
|
|
|
|
#3 |
|
Junior Member (25+)
Join Date: Dec 2009
Location: Montana
Age: 67
Posts: 66
Thanks: 4
Thanked 10 Times in 8 Posts
Rep Power: 1
![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
I don't know the answer to your question, directly, however you need to know a couple of things. First by the time XP rolled around, the batch language had improved considerably. Many more commands were added, to the point where you can actually do things with it, now.
My best advice is to Google for "Windows-XP Command Line" and then dig in. There's a lot of good stuff out there. I have a 720 page command-line reference in PDF form that's a killer. The file name is: 11390771-Windows-Xp-Command-Line.pdf and it includes about everything there is to know about it. There's also some short command references, etc. Have fun. |
|
|
|
|
|
#4 |
|
Junior Member (25+)
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0
![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
i am good with batch files, i dont get what your saying when i do that it doesn't ask for yn
|
|
|
|
|
|
#5 |
|
Junior Member (25+)
Join Date: Dec 2009
Location: Montana
Age: 67
Posts: 66
Thanks: 4
Thanked 10 Times in 8 Posts
Rep Power: 1
![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
Did a Google search on "Batch File Enhancers" got a lot of good stuff. Reminds me of the Norton Utilities "BE" command that allows all sorts of good things. PC Magazine's DOS Utilities had a couple of similar enhancers, like "get".
There should be a way of inserting a timed break between tasks in the batch file that would allow you to press a key to stop or redirect the batch file execution, or allow it to continue. In BE you would use the timed ask function "TASK". Finally, there's the very commercial "WinBatch". For $99us not recommended unless you're desperate. This site has many good links: Article: Turbo-charge your batch-file commands. (tutorial) | AccessMyLibrary - Promoting library advocacy |
|
|
|
|
|
#6 |
|
Junior Member (25+)
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0
![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
its "echo y | TASKKILL /IM cmd.exe"
|
|
|
|
|
|
#7 |
|
Founder
![]() Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 371
Thanked 411 Times in 356 Posts
Rep Power: 67
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
This will just terminate the cmd.exe, right?
|
|
|
|
|
|
#8 |
|
Junior Member (25+)
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0
![]() OS:
|
Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C
yes it will kill the cmd process so all windows that are running on cmd.exe will crash you can make a batch file that will kill cmd then compile it and it will not crash
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |