You can execute MPS code not only from within MPS but also from command line. This can come useful for batch processing or when exporting models from MPS.

There are two options for running code from command line:

  • Using an MPS-provided Ant task.
  • Writing custom code using MPS libraries.

Using MPS-provided Ant task

This approach is documented in the JetBrains MPS Help. It’s quite simple to set up so you can be up and running quickly. However, as soon as you need to pass command-line arguments to your code you will find yourself out of luck. The mpsMain method that you write has no args parameter, nor does the generated Ant script pass any path macros or system properties to the program. The only way to pass arguments seems to be via a temporary file or perhaps an environment variable.

Writing custom code

This approach is documented in the mbeddr Wiki. The benefit of writing your own code is flexibility: you can control the MPS configuration, you can use command-line arguments, you can basically do whatever you want. A downside is that it’s more complicated to set up: you need to set up the proper Java classpath for the program to run.