private void dealCallExe(IWebSocketConnection socket, CallExeCo co) { // exe 调用服务 CallExeServer exeServer = new CallExeServer(); // 响应数据对象 CallExeCro exeCro = new CallExeCro(); exeCro.Uuid = co.Uuid; if (co.Async) { logReqMsg(socket, "exePath:" + co.ExePath + ", Args:" + string.Join(",", co.Args), co.Uuid); // CallExeOutputHandler outputHandler = new CallExeOutputHandler(); // async exeServer.asyncCallExe(co.ExePath, co.Args, output => { Console.WriteLine("output:" + output); // 每次只输出一行,因此需要动态添加"\n" exeCro.Output += output + "\n"; }, exitCode => { Console.WriteLine("exitCode:" + exitCode); exeCro.ExitCode = exitCode; if (exeCro.Output != null && exeCro.Output.Length >= 1) { // 去除最后一个"\n" exeCro.Output = exeCro.Output.Substring(0, exeCro.Output.Length - 1); } // logResMsg(socket, "exitCode:"+ exeCro.ExitCode + ", output:"+ exeCro.Output, co.Uuid); // 异步调用结束 socket.Send(CommunicateUtils.communicateVoToStr(exeCro)); }, error => { Console.WriteLine("error:" + error); exeCro.Error += error; }); } else { // sync string[] ret = exeServer.syncCallExe(co.ExePath, co.Args); Console.WriteLine("exitCode:{0}, ouput:{1}, error:{2}", ret[0], ret[1], ret[2]); exeCro.ExitCode = int.Parse(ret[0]); exeCro.Output = ret[1]; exeCro.Error = ret[2]; socket.Send(CommunicateUtils.communicateVoToStr(exeCro)); } }
private void dealCallExe(Socket socket, CallExeCo co) { CallExeServer exe = new CallExeServer(); if (co.Async) { CallExeCro exeCro = new CallExeCro(); string uuid = logReqMsg(socket, "exePath:" + co.ExePath + ", Args:" + string.Join(",", co.Args)); // CallExeOutputHandler outputHandler = new CallExeOutputHandler(); // async exe.asyncCallExe(co.ExePath, co.Args, delegate(string output) { Console.WriteLine("output:" + output); // 每次只输出一行,因此需要动态添加"\n" exeCro.Output += output + "\n"; }, delegate(int exitCode) { Console.WriteLine("exitCode:" + exitCode); exeCro.ExitCode = exitCode; if (exeCro.Output != null && exeCro.Output.Length >= 1) { // 去除最后一个"\n" exeCro.Output = exeCro.Output.Substring(0, exeCro.Output.Length - 1); } logResMsg(socket, "exitCode:" + exeCro.ExitCode + ", output:" + exeCro.Output, uuid); // 异步调用结束 AsyncServerSocket.getInstance().Send(socket, exeCro); }, delegate(string error) { Console.WriteLine("error:" + error); exeCro.Error += error; }); //string[] ret = exe.asyncCallExe(co.ExePath, co.Args,null); } else { // sync string[] ret = exe.syncCallExe(co.ExePath, co.Args); Console.WriteLine("exitCode:{0}, ouput:{1}, error:{2}", ret[0], ret[1], ret[2]); CallExeCro exeCro = new CallExeCro(); exeCro.ExitCode = int.Parse(ret[0]); exeCro.Output = ret[1]; exeCro.Error = ret[2]; AsyncServerSocket.getInstance().Send(socket, exeCro); } }