.NET (4) class library for executing a command line program.
C#
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ExecuteCommandLineProgram
.gitignore
ExecuteCommandLineProgram.sln
README.md

README.md

Overview of the ExecuteCommandLineProgram Library

ExecuteCommandLineProgram is a .NET (4) class library for executing command line programs.

The code was copied and slightly modified from this answer to the Stack Overflow question How to capture Shell command output in C#?.

This answer to the Stack Overflow question run interactive command line exe using c# provided the necessary resource info for me to add support for supporting standard-input input.

Example usage:

CommandLineProgramProcessResult result =
	CommandLineProgramProcess.RunProgram(
		@"C:\Program Files (x86)\SomeFolder\SomeProgram.exe",				// Path of executable program
		@"C:\Program Files (x86)\SomeFolder\",								// Path of working directory
		String.Format(@"""{0}""", filePathThatNeedsToBeQuotedArgument),		// Command line arguments
		10 * 60 * 1000);													// Timeout, in milliseconds
		
string standardError = result.StandardError;
string standardOutput = result.StandardOutput;
int exitCode = result.ExitCode;

Example usage for supplying input via standard input:

CommandLineProgramProcessResult result =
	CommandLineProgramProcess.RunProgram(
		@"C:\Program Files (x86)\SomeFolder\SomeProgram.exe",				// Path of executable program
		@"C:\Program Files (x86)\SomeFolder\",								// Path of working directory
		String.Format(@"""{0}""", filePathThatNeedsToBeQuotedArgument),		// Command line arguments
		10 * 60 * 1000,														// Timeout, in milliseconds
		inputData);															// Standard-input input, as a string
		
string standardError = result.StandardError;
string standardOutput = result.StandardOutput;
int exitCode = result.ExitCode;