Class ProcessExecutor
- Namespace
- JD.AI.Core.Infrastructure
- Assembly
- JD.AI.Core.dll
Unified process execution utility. Replaces duplicated ProcessStartInfo patterns across GitTools, ShellTools, BrowserTools, ClipboardTools, GitHubTools, etc.
public static class ProcessExecutor
- Inheritance
-
ProcessExecutor
- Inherited Members
Fields
DefaultTimeout
Default timeout for process execution.
public static readonly TimeSpan DefaultTimeout
Field Value
Methods
IsAvailableAsync(string, CancellationToken)
Checks whether a CLI tool is available on the system PATH.
public static Task<bool> IsAvailableAsync(string toolName, CancellationToken cancellationToken = default)
Parameters
toolNamestringcancellationTokenCancellationToken
Returns
RunAsync(string, string, string?, TimeSpan?, string?, IReadOnlyDictionary<string, string>?, bool, CancellationToken)
Runs a process asynchronously, capturing stdout and stderr.
public static Task<ProcessResult> RunAsync(string fileName, string arguments = "", string? workingDirectory = null, TimeSpan? timeout = null, string? standardInput = null, IReadOnlyDictionary<string, string>? environmentVariables = null, bool clearEnvironment = false, CancellationToken cancellationToken = default)
Parameters
fileNamestringThe executable to run.
argumentsstringCommand-line arguments.
workingDirectorystringOptional working directory.
timeoutTimeSpan?Optional timeout (defaults to 30s).
standardInputstringOptional text to write to stdin.
environmentVariablesIReadOnlyDictionary<string, string>Optional extra environment variables.
clearEnvironmentboolWhen true, clears inherited environment variables before adding
environmentVariables. Used by sandboxes to strip sensitive vars.cancellationTokenCancellationTokenCancellation token.
Returns
- Task<ProcessResult>
A ProcessResult with exit code, stdout, and stderr.
RunForOutputAsync(string, string, string?, TimeSpan?, CancellationToken)
Runs a process and returns only stdout, or an error-prefixed message on failure. Convenience method matching the common tool pattern.
public static Task<string> RunForOutputAsync(string fileName, string arguments = "", string? workingDirectory = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)
Parameters
fileNamestringargumentsstringworkingDirectorystringtimeoutTimeSpan?cancellationTokenCancellationToken
Returns
ShellOpen(string)
Opens a file or URL using the system shell (non-redirected).
public static void ShellOpen(string target)
Parameters
targetstring