Table of Contents

Class ProcessRunner

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Safe process execution helper that prevents command injection by always using ArgumentList (never string-concatenated arguments). All process spawning in the framework should go through this class.

public static class ProcessRunner
Inheritance
ProcessRunner
Inherited Members

Methods

CanRun(string, IEnumerable<string>, int)

Checks if a given executable can be found and run (exits without error).

public static bool CanRun(string executable, IEnumerable<string> arguments, int timeoutMs = 10000)

Parameters

executable string

The executable name or path.

arguments IEnumerable<string>

Arguments for the probe invocation.

timeoutMs int

Maximum time to wait.

Returns

bool

True if the process started and exited successfully.

RunAndReadOutput(string, IEnumerable<string>, int)

Runs a process with the given arguments and returns its stdout content. Arguments are passed individually via ArgumentList to prevent injection.

public static string RunAndReadOutput(string executable, IEnumerable<string> arguments, int timeoutMs = 10000)

Parameters

executable string

The executable name or path.

arguments IEnumerable<string>

Individual arguments (not shell-joined).

timeoutMs int

Maximum time to wait for the process to exit.

Returns

string

The process stdout output, or empty string on failure.

RunWithInput(string, IEnumerable<string>, string, int)

Runs a process with the given arguments, writes input to stdin, and waits for exit.

public static void RunWithInput(string executable, IEnumerable<string> arguments, string stdinInput, int timeoutMs = 10000)

Parameters

executable string

The executable name or path.

arguments IEnumerable<string>

Individual arguments (not shell-joined).

stdinInput string

Content to write to the process stdin.

timeoutMs int

Maximum time to wait for the process to exit.

StartProcess(string, IEnumerable<string>, bool, bool, bool)

Starts a long-running process (e.g., ffmpeg) and returns it for stream-based I/O. The caller is responsible for disposing the process.

public static Process? StartProcess(string executable, IEnumerable<string> arguments, bool redirectStdin = false, bool redirectStdout = false, bool redirectStderr = false)

Parameters

executable string

The executable name or path.

arguments IEnumerable<string>

Individual arguments.

redirectStdin bool

Whether to redirect stdin.

redirectStdout bool

Whether to redirect stdout.

redirectStderr bool

Whether to redirect stderr.

Returns

Process

The started process, or null if it failed to start.