You can do this, but it's quite difficult. You have to ensure that the commands are properly formatted, and that the config files for your MAME frintend are properly designed, too. You can use the
os.execute() command to run external commands. Here's a question with a good answer on the topic.