Q:

Force MEL script to WAIT until previous command completes

I'm trying to write a Maya MEL batch script involving a texture bake operation, followed by a file save operation.  This is all placed in a for loop.
The script works if executed line by line.  But in a loop, what is happening is, it seems the bake is taking too long, so the file that is expected to be generated (testComp.000I.iff, where I is the frame #) is not present by the time the file save operation executes.  So the script doesn't work actually.
How do you force Maya to WAIT until the previous command completes, before trying to execute the next line?

A:

A MEL script does wait until the previous command completes.
The only exception to this rule is when a mel script generates ANOTHER mel command, as is the case with the MEL bake command, convertLightmapSetup. convertLightmapSetup spawns a call to convertLightmap as it runs, and that call does not block.
So you have to call convertLightmap directly, for your script to block.

