一、核心代碼如下
/// <summary>
/// 打開自己開發的程序
/// </summary>
/// <param name="fileName">文件名稱(比如C-MES.exe)</param>
/// <param name="filePath">文件所在路徑(比如G:\SoftWare\DMMES)</param>
public static void OpenOtherEXEMethod(string fileName, string filePath)
{
if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(filePath))
{
//開啓一個新process
System.Diagnostics.ProcessStartInfo p = null;
System.Diagnostics.Process proc;
p = new System.Diagnostics.ProcessStartInfo(fileName);
p.WorkingDirectory = filePath;//設置此外部程序所在windows目錄
proc = System.Diagnostics.Process.Start(p);//調用外部程序
}
}
二、使用方法
public class Test_OpenMES : MonoBehaviour
{
public string mesName = @"C-MES.exe";
public string mesPath = @"G:\SoftWare\DMMES";
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("開始打開MES系統");
OpenOtherEXE.OpenOtherEXEMethod(mesName, mesPath);
}
}
}