create a file, command.txt and add to it
connect WWWThreads;
select * from w3t_Boards;
mysql < command.txt > dump.txt
that should take the commands from command.txt, execute, and then send the output to dump.txt
Depending on your security you may need to add the -u and -p options to the mysql comamnd.
If you are using a UNIX shell
mysql <<EOD >dump.txt
connect WWWThreads;
select * from w3t_Posts;
EOD
may also work from within your script.
this may also help: http://www.mysql.com/doc/B/a/Batch_mode.html
Rob