- Home /
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!
Answer by tanoshimi · Dec 06, 2015 at 03:25 PM
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);
}
Hi,
Thanks for the answer. I've tried doing this just now but doesn't seem to be doing anything, but also get no compiler errors. The program in question is one that is usually run in the ter$$anonymous$$al, so perhaps getting Unity to open a ter$$anonymous$$al and run the program in that might do it?
Answer by william-hoopes-wb · Aug 03, 2017 at 04:56 PM
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.
Your answer
Follow this Question
Related Questions
How to open unity solution with some specific inputs (command line or from website javascript) ? 1 Answer
How can I add an Input Axis from a script, input coming from an external program? 0 Answers
Connecting scenes 3 Answers
How to dynamically access scripts from other gameobjects? 1 Answer
Is there any way to link an image object to another game object's component? 0 Answers