public static void ExecuteScript(ProcessRequest request) { EditorUtility.DisplayProgressBar("UnityBuilder.ExternalToolKit", $"ExecuteScript:{request.ScriptFilePath}", 0f); int exitCode = -1; try { var process = CreateProcess(request); BuildLogger.Log($"[{request.ProcessArguments}]"); process.Start(); string message = process.StandardOutput.ReadToEnd(); process.WaitForExit(); exitCode = process.ExitCode; process.Dispose(); System.IO.File.WriteAllText(request.LogFilePath, message); } catch (Exception e) { throw e; } finally { EditorUtility.ClearProgressBar(); request.Callback?.Invoke(new ProcessResult { ExitCode = exitCode }); } }
static Process CreateProcess(ProcessRequest request) { var p = new Process(); p.StartInfo.FileName = ProcessFileName; p.StartInfo.Arguments = request.ProcessArguments; p.StartInfo.CreateNoWindow = true; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.StandardOutputEncoding = Encoding.UTF8; return(p); }