From db3fd11cb26c9318f90f3f1e6ad7babafaf3d8e4 Mon Sep 17 00:00:00 2001 From: tpxxn <351765204@qq.com> Date: Mon, 17 Mar 2025 00:23:22 +0800 Subject: [PATCH] =?UTF-8?q?ShellHelper=20=E5=9C=A8=20Unity=20=E8=BE=93?= =?UTF-8?q?=E5=87=BA=20Log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TEngine/Editor/Utility/ShellHelper.cs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs b/UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs index 74d3cfd6..6881af31 100644 --- a/UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs +++ b/UnityProject/Assets/TEngine/Editor/Utility/ShellHelper.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Collections.Generic; +using System.Text; namespace TEngine.Editor { @@ -102,12 +103,52 @@ namespace TEngine.Editor process.Close(); } } - + public static void RunByPath(string path) { if (!string.IsNullOrEmpty(path)) { - Process.Start(path); + try + { + Process process = new Process(); + ProcessStartInfo startInfo = new ProcessStartInfo(path) + { + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + // 添加编码设置,确保中文正确显示 + StandardOutputEncoding = Encoding.UTF8, + StandardErrorEncoding = Encoding.UTF8 + }; + + process.StartInfo = startInfo; + process.OutputDataReceived += (_, args) => + { + if (args.Data != null) + { + UnityEngine.Debug.Log($"[Process Output]: {args.Data}"); + } + }; + process.ErrorDataReceived += (_, args) => + { + if (args.Data != null) + { + UnityEngine.Debug.LogError($"[Process Error]: {args.Data}"); + } + }; + + process.Start(); + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + + UnityEngine.Debug.Log($"Started process with ID: {process.Id} for path: {path}"); + } + catch (Exception e) + { + UnityEngine.Debug.LogError($"Error starting process at path {path}: {e.Message}"); + UnityEngine.Debug.LogException(e); + } } } }