Execute External Program

Hello!

So I have a pretty general question, mostly related to my lack of concrete coding knowledge. Basically, I’m currently working on a physics program which can generate predictions for the LHC. The problem one always gets with these sorts of programs is that nice user interfaces just basically don’t exist.

What I would like to do is use Unity to have a link between the user and the program. At the very least, I would like to be able to call my physics program from within Unity. If I can do this, then I can use Unity to get the information from the user regarding the input paramters, execute the program and (possibly) do something fancy while the program runs.

The question is - how can I execute an external program from within Unity?

Cheers!

Use Process.Start from the System.Diagnostics namespace. Something like this:

using System.Diagnostics;
....
void LoadYourPhysicsProgram() {
  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.FileName = "PHYSICSPROGRAM.EXE";
  StartInfo.Arguments = "Extra Arguments to Pass to the Program";
  Process.Start(startInfo);
}

A little late to this party, but for others coming across this, what I’ve found that works best is to write a bat/sh file to disk, and run that instead. When using Process.Start(), you don’t get the context you would have when running from a shell (ie PATH variables, etc). Using Process expects you to fill that in (at least from Unity). By writing a bat/sh script to disk, and then running it, you’re taking advantage of the system providing that context for you.