From a0a5a08bdf187ddcaebbcdce96e869212c7b870f Mon Sep 17 00:00:00 2001 From: "Dear.Va" <1328886154@qq.com> Date: Wed, 29 Mar 2023 21:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCommandLine=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ChatShell.Core/Models/ProcessConfigure.cs | 17 ++++++++++++++--- src/ChatShell/Program.cs | 2 +- src/publish-linux-x64.bat | 1 + src/publish-win-x64.bat | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/publish-linux-x64.bat create mode 100644 src/publish-win-x64.bat diff --git a/src/ChatShell.Core/Models/ProcessConfigure.cs b/src/ChatShell.Core/Models/ProcessConfigure.cs index bf4070c..0be25e0 100644 --- a/src/ChatShell.Core/Models/ProcessConfigure.cs +++ b/src/ChatShell.Core/Models/ProcessConfigure.cs @@ -1,9 +1,11 @@ using System.Diagnostics; +using System.Text; +using System.Text.RegularExpressions; namespace ChatShell.Core.Models; [Serializable] -public class ProcessConfigure { +public partial class ProcessConfigure { public required string Name { get; init; } public required string CommandLine { get; init; } @@ -17,9 +19,15 @@ public class ProcessConfigure { public string? WorkingDirectory { get; init; } public ProcessStartInfo ToStartInfo(string arguments) { + var commands = SplitBySpace().Split(CommandLine); + var argumentsBuilder = new StringBuilder(); + foreach (var command in commands.Skip(1)) { + argumentsBuilder.Append(command).Append(' '); + } + return new ProcessStartInfo { - FileName = CommandLine, - Arguments = arguments, + FileName = commands[0], + Arguments = argumentsBuilder.Append(arguments).ToString(), WorkingDirectory = WorkingDirectory, CreateNoWindow = true, UseShellExecute = false, @@ -28,4 +36,7 @@ public ProcessStartInfo ToStartInfo(string arguments) { RedirectStandardInput = true, }; } + + [GeneratedRegex(@"[ ](?=(?:[^""]*""[^""]*"")*[^""]*$)")] + private static partial Regex SplitBySpace(); } \ No newline at end of file diff --git a/src/ChatShell/Program.cs b/src/ChatShell/Program.cs index ede74ea..99244ad 100644 --- a/src/ChatShell/Program.cs +++ b/src/ChatShell/Program.cs @@ -10,7 +10,7 @@ public static class Program { private static readonly CancellationTokenSource CancellationTokenSource = new(); public static async Task Main(string[] args) { - var fs = File.OpenRead("./AppConfigure.json"); + var fs = File.OpenRead(Path.Combine(Path.GetDirectoryName(Environment.ProcessPath.NotNull()).NotNull(), "AppConfigure.json")); var configure = (await JsonSerializer.DeserializeAsync(fs)).NotNull("Invalid AppConfigure.json"); await fs.DisposeAsync(); diff --git a/src/publish-linux-x64.bat b/src/publish-linux-x64.bat new file mode 100644 index 0000000..99037f7 --- /dev/null +++ b/src/publish-linux-x64.bat @@ -0,0 +1 @@ +dotnet publish -r linux-x64 -c Release --self-contained \ No newline at end of file diff --git a/src/publish-win-x64.bat b/src/publish-win-x64.bat new file mode 100644 index 0000000..58e4890 --- /dev/null +++ b/src/publish-win-x64.bat @@ -0,0 +1 @@ +dotnet publish -r win-x64 -c Release --self-contained \ No newline at end of file