- //打开外部程序
- public void StartExe(){
- //获取路径
- string dir=Environment.CurrentDirectory;
- ProcessStartInfo pi=new ProcessStartInfo();
- pi.FileName=dir+"/1.exe";
- pi.Argrments=js.ToJson();//传递json
- vrar=Process.Start(pi);//获取进程
- //绑定外部程序关闭的事件
- vrar.EnableRaisingevents=true;
- vrar.Exited+=new EventHandler(VRARExit);
- //外部程序获取焦点
- SetForegroundWindow(vrar.MainWindowHandle);
- }
- [DllImport("USER32.DLL")]
- public static extern bool SetForegroundWindow(IntPtr mainWindowHandle);
- void VRARExit(obect sender,EventArgs e){
- Debug.Log("外部程序已经关闭");
- }
- //外部程序接收参数
- private static void ReceiveJson(){
- string[] args=Environment.GetCommandLineArgs();//获取参数
- string str="";
- for(int i=1;i<args.Length;i++){
- str+=args[i];
- }
- JsonData js=JsonMapper.ToObject(str);//转换成json
- }