How do I get a python script to run after the .blend file loads from the command line? I am using this command line:

blender -P test.py test.blend


and test.py has:

import bpy
for scene in bpy.data.scenes:
    scene.render.image_settings.file_format = "FFMPEG"


If I run with just this command line:

blender -P test.py


the file format is set just fine. But if I put the blender file back in the command line, the file format is not changed. My interpretation is that the .py file is run before the .blend file is loaded. Whether or not my interpretation is correct, how can I make this happen the way I want it to?

Additional information: This is a stand-along render server for high school students and I need to ensure that a number of things are set correctly and not just the file format.
Command line arguments are run in the order they are given. So at the minute, yes, the Python file is being run and then the 'test.blend' file is being opened.

To fix this you just need to put the blend file part of the command first and the Python file after:

blender test.blend -P test.py


Now your file is opened then the Python commands are run in that opened file.