Skip to content

Commit c09767f

Browse files
authored
fix: use ArgumentList for Process.Start to handle spaces in paths (#62)
1 parent 3289587 commit c09767f

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/Services/SimulationService.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,15 @@ public async Task<SimulationResult> RunAsync(
8585
// 5. Run client
8686
Log("STEP 5: Running Client.exe", progress);
8787
var clientExe = Path.Combine(config.OutputDirectory, "Client.exe");
88-
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";
88+
var clientArgs = new List<string>
89+
{
90+
"--server-url", _server.BaseUrl,
91+
"--install-path", config.AppDirectory,
92+
"--current-version", config.CurrentVersion,
93+
"--app-secret", config.AppSecretKey,
94+
"--product-id", config.ProductId,
95+
"--app-name", "Upgrade.exe"
96+
};
8997
var clientResult = await RunExe(clientExe, clientArgs, ct);
9098
Log(clientResult.Output, progress);
9199

@@ -163,14 +171,16 @@ private void Validate(SimulateConfigModel config)
163171
catch { throw new InvalidOperationException("dotnet CLI not found"); }
164172
}
165173

166-
private async Task<(bool Success, string Output)> RunExe(string exePath, string arguments, CancellationToken ct)
174+
private async Task<(bool Success, string Output)> RunExe(string exePath, List<string> arguments, CancellationToken ct)
167175
{
168-
var psi = new ProcessStartInfo(exePath, arguments)
176+
var psi = new ProcessStartInfo(exePath)
169177
{
170178
RedirectStandardOutput = true, RedirectStandardError = true,
171179
StandardOutputEncoding = Encoding.UTF8, StandardErrorEncoding = Encoding.UTF8,
172180
UseShellExecute = false, CreateNoWindow = true
173181
};
182+
foreach (var arg in arguments)
183+
psi.ArgumentList.Add(arg);
174184
using var p = Process.Start(psi)!;
175185
var output = new StringBuilder();
176186
var readTask = Task.Run(async () => { while (!p.StandardOutput.EndOfStream) output.AppendLine(await p.StandardOutput.ReadLineAsync(ct)); }, ct);

0 commit comments

Comments
 (0)