Note that if you prefer to do the conversion via a script, Calibre includes command-line scripts.
The one for book conversions is called ebook-convert.exe and is under the main Calibre directory.
This page describes how to use the various commands:
http://calibre-ebook.com/user_manual/cli/cli-index.html
Mitch