Tags

, , , ,

I have spent the day doing various ant builds. I leave the build running and sometimes don’t notice that it has finished or failed along the way.

Wouldn’t it be nice if the ant script went beep on success or failure? Well at the Windows 7  command prompt you can do

prompt> (CALL ant dist && (echo ^G)) || (echo ^G^G^G)

and this will sound a one bell (control G) if the command succeeded and two bells if it fails. Note the use of the CALL command; this is necessary because ant is a batch file and if you don’t use CALL it does not return properly and the conditional operators do not work.

But I promised you rich wav sounds not crude beeps. We can do that too thanks to  Eli Fulkerson who wrote sounder.exe

This is a small console program that can be invoked to play a .wav file from the command line. As compiled, it will only play the first 2 seconds of the .wav and then exit, but that’s tweakable in the source. It was written simply to provide audible alerts from windows batch files.

via sounder.exe – play a wav file from the command line.

This runs fine on my 64 bit Windows 7.

Simply copy some .wav files from your Windows directory. I like chord.wav for errors and chimes.wav for success.

prompt> (CALL ant dist && (sounder.exe chimes.wav)) || (sounder.exe chord.wav)

and then for optimum reuse create some batch files giving

prompt> (CALL ant dist && (beep-success.bat)) || (beep-error.bat)

where these files are in C:\batch and this has been added to your path.

–updated 2011-06-09

The final example above works fine unless you want to include this line in a batch file. If you do you will find that the next line of the batch file does not run. This is because control of execution does not return from a batch file unless you use CALL. Therefore

prompt> (CALL ant dist && (CALL beep-success.bat)) || (CALL beep-error.bat)

is better for reuse.

Advertisements