Friday 29 February 2008

Simple tricks for Windows Programming automation using batch files

I thought I might mention a few of the simple tricks I use when I am developing...


Keyboard assigned Shortcuts


I often need to restart apache very regularly, ie: every other minute.


This is a real bore when I have to find either a GUI or and command prompt. So I set up shortcuts in windows..


I create batch files to do what ever I want, create a shortcut to the batch file and then assign key strokes to them.


ie:


CTRL+SHIFT+F9 => start apache service


CTRL+SHIFT+F10 => stop apache service


Then all I need to do is keep an eye on the Apache Monitor.


NOTE: You must put the shortcuts in a folder in your Start menu... otherwise they will never run when you hit the assigned keys.


While it seems simple, I have noticed how few people truly automate the tasks they perform again and again and again....


Do it.
This alone saves me hours every week when I have my head in code.


 


Automating a task with Batch file and viewing the results


Use set /p varName="ask for data" then use the variable to call the correct thing.


You can also use this to stop the box from closing, so you can see the results, put this at the end: set /P Done="Press return to close."


Here is an example for an ant build:


@echo off
set /P TARGET="Please enter Target(clean,compile,build,run,javadoc):"
CMD /C ant %TARGET%
echo -------------------------------------------
set /P Done="Press return to close."
:End

1 comment: