TechTalkz.com Logo Ask the Expert

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Software World > Programming

Notices

Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C

Programming


Reply
 
Thread Tools Display Modes
Old 26-11-2009, 08:51 PM   #1
Newbie
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 susja is an unknown quantity at this point
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.
susja is offline   Reply With Quote
Old 26-11-2009, 09:10 PM   #2
Founder
 
Strider's Avatar
 
Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 371
Thanked 411 Times in 356 Posts
Rep Power: 67 Strider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just Great


OS: Windows XP Windows Server 2003 / Windows Server 2008 Windows Vista Windows 7 Linux


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.
Strider is offline   Reply With Quote
Old 15-01-2010, 04:29 AM   #3
Junior Member (25+)
 
davnel's Avatar
 
Join Date: Dec 2009
Location: Montana
Age: 67
Posts: 66
Thanks: 4
Thanked 10 Times in 8 Posts
Rep Power: 1 davnel is on a distinguished road


OS: Windows 98 / Windows ME Windows NT / Windows 2000 Windows XP Windows 7 Linux


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.
davnel is offline   Reply With Quote
Old 06-02-2010, 08:38 PM   #4
Junior Member (25+)
 
killer64's Avatar
 
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0 killer64 is an unknown quantity at this point


OS: Windows NT / Windows 2000 Windows XP Linux


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
killer64 is offline   Reply With Quote
Old 06-02-2010, 10:37 PM   #5
Junior Member (25+)
 
davnel's Avatar
 
Join Date: Dec 2009
Location: Montana
Age: 67
Posts: 66
Thanks: 4
Thanked 10 Times in 8 Posts
Rep Power: 1 davnel is on a distinguished road


OS: Windows 98 / Windows ME Windows NT / Windows 2000 Windows XP Windows 7 Linux


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
davnel is offline   Reply With Quote
Old 07-02-2010, 04:59 PM   #6
Junior Member (25+)
 
killer64's Avatar
 
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0 killer64 is an unknown quantity at this point


OS: Windows NT / Windows 2000 Windows XP Linux


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"
killer64 is offline   Reply With Quote
Old 08-02-2010, 03:01 PM   #7
Founder
 
Strider's Avatar
 
Join Date: Nov 2005
Location: The Last City Zion!
Posts: 3,876
Thanks: 371
Thanked 411 Times in 356 Posts
Rep Power: 67 Strider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just GreatStrider is just Great


OS: Windows XP Windows Server 2003 / Windows Server 2008 Windows Vista Windows 7 Linux


Re: Trap in a batch file - How to execute a command after stopping a batch file using Ctrl+C

Quote:
Originally Posted by killer64 View Post
its "echo y | TASKKILL /IM cmd.exe"
This will just terminate the cmd.exe, right?
Strider is offline   Reply With Quote
Old 09-02-2010, 11:48 AM   #8
Junior Member (25+)
 
killer64's Avatar
 
Join Date: Feb 2010
Posts: 71
Thanks: 7
Thanked 2 Times in 2 Posts
Rep Power: 0 killer64 is an unknown quantity at this point


OS: Windows NT / Windows 2000 Windows XP Linux


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
killer64 is offline   Reply With Quote
Reply

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 09:24 AM.


vBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2010, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional