Mental Ray: How do I generate .mi files from the command line or with a script?

The following command takes a Maya scene and generates .mi files:

maya -batch -command “Mayatomr -mi -pf 2 -file .mi -xp rrarrarrrr” -file

Replace with the name of the output .mi files and with the Maya scene file.

The command can be included in a script or executed from a command line.