Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
.NET (4) class library for executing a command line program.
branch: master

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;
Something went wrong with that request. Please try again.