diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-09 23:48:17 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-09 23:48:17 +0800 |
| commit | 6dedba9e3cedf6463f25460eba84111d6a0bd0dd (patch) | |
| tree | 4dcc6855ada5b28e20835ab60800c1028e505f7a /CommandLineWrapper/JVCSCommandInvoker.cs | |
| parent | 6b9268d2d88c81c18f2cc21e343d321989dad99c (diff) | |
Add command line wrapper for JVCS operations
Diffstat (limited to 'CommandLineWrapper/JVCSCommandInvoker.cs')
| -rw-r--r-- | CommandLineWrapper/JVCSCommandInvoker.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/CommandLineWrapper/JVCSCommandInvoker.cs b/CommandLineWrapper/JVCSCommandInvoker.cs new file mode 100644 index 0000000..56d67ca --- /dev/null +++ b/CommandLineWrapper/JVCSCommandInvoker.cs @@ -0,0 +1,41 @@ +using System.Diagnostics; +using CommandLineWrapper; + +public static class JVCSCommandInvoker +{ + // Structure to hold the result of a command invocation + public struct InvokeResult + { + public int ExitCode { get; set; } + public string StandardOutput { get; set; } + } + + // Invokes a command-line process with the given arguments and optional working directory + public static async Task<InvokeResult> Invoke(string[] args, string? workingDirectory = null) + { + var startInfo = new ProcessStartInfo + { + FileName = Constants.CommandLinePath.FullName, + Arguments = string.Join(" ", args), + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + if (!string.IsNullOrEmpty(workingDirectory)) + startInfo.WorkingDirectory = workingDirectory; + + using (var process = new Process { StartInfo = startInfo }) + { + process.Start(); + string output = await process.StandardOutput.ReadToEndAsync(); + await process.WaitForExitAsync(); + + return new InvokeResult + { + ExitCode = process.ExitCode, + StandardOutput = output.Trim() + }; + } + } +} |
