- Home /
Running external program from c# code
Hi! i have a program on Unity and i'd like to open an external demo through my c#script. This demo is located in a different folder and to run it i normally open cdm window and write commands from there. Now i'd like everything to be done autommatically and managed by the script. So i've tried this:
string demo = "demo";
string Root = @"C:\Users\...\Desktop\Folder\";
// call cmd and run original menge simulation
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
// at this point it opens the cmd window correctly
startInfo.Arguments = System.String.Format( @"/k cd {0}\Exe", Root );
// here it correctly changes the directory
startInfo.Arguments = System.String.Format( @"/k menge -p ..\examples\core\{0}.xml", demo);
// here is the problem
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
When i run this code, cmd shows "menge is not recognized as an internal or external command operable program or batch file" and it sets back the directory of my unity project. The point is that if i comment the second startInfo.Arguments (so if i change the directory from code and then write manually the second command directly on cmd window), it works perfectly. But i'd like everything to be done automatically by the code, without writing anything on cmd. It seems the problem has to do with executing multiple command lines, but probably due to my lack of deep coding knowledge, i can't get how. Any idea of what i'm doing wrong? Really thanks in advance
replace menge with the full path for your external program c://programs files/../menge.exe
Your answer
![](https://koobas.hobune.stream/wayback/20220612140608im_/https://answers.unity.com/themes/thub/images/avi.jpg)