From 76cb7ae037299043bcfbb7a9c56e923c025aeb29 Mon Sep 17 00:00:00 2001 From: JusterZhu Date: Thu, 21 May 2026 03:07:06 +0800 Subject: [PATCH] fix: use ArgumentList for Process.Start to handle spaces in paths --- src/Services/SimulationService.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Services/SimulationService.cs b/src/Services/SimulationService.cs index 91bc092..ab757ee 100644 --- a/src/Services/SimulationService.cs +++ b/src/Services/SimulationService.cs @@ -85,7 +85,15 @@ public async Task RunAsync( // 5. Run client Log("STEP 5: Running Client.exe", progress); var clientExe = Path.Combine(config.OutputDirectory, "Client.exe"); - var clientArgs = $"--server-url {_server.BaseUrl} --install-path \"{config.AppDirectory}\" --current-version {config.CurrentVersion} --app-secret {config.AppSecretKey} --product-id {config.ProductId} --app-name Upgrade.exe"; + var clientArgs = new List + { + "--server-url", _server.BaseUrl, + "--install-path", config.AppDirectory, + "--current-version", config.CurrentVersion, + "--app-secret", config.AppSecretKey, + "--product-id", config.ProductId, + "--app-name", "Upgrade.exe" + }; var clientResult = await RunExe(clientExe, clientArgs, ct); Log(clientResult.Output, progress); @@ -163,14 +171,16 @@ private void Validate(SimulateConfigModel config) catch { throw new InvalidOperationException("dotnet CLI not found"); } } - private async Task<(bool Success, string Output)> RunExe(string exePath, string arguments, CancellationToken ct) + private async Task<(bool Success, string Output)> RunExe(string exePath, List arguments, CancellationToken ct) { - var psi = new ProcessStartInfo(exePath, arguments) + var psi = new ProcessStartInfo(exePath) { RedirectStandardOutput = true, RedirectStandardError = true, StandardOutputEncoding = Encoding.UTF8, StandardErrorEncoding = Encoding.UTF8, UseShellExecute = false, CreateNoWindow = true }; + foreach (var arg in arguments) + psi.ArgumentList.Add(arg); using var p = Process.Start(psi)!; var output = new StringBuilder(); var readTask = Task.Run(async () => { while (!p.StandardOutput.EndOfStream) output.AppendLine(await p.StandardOutput.ReadLineAsync(ct)); }, ct);