fahadash / ConsoleSharp

Command Line Helper for .NET, Written in C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ConsoleSharp

Console Helper for .NET, Written in C#

You can use these helper classes to run console-based command-line utilities and capture their outputs. Currently there are two kinds of helpers, one uses Reactive-Extensions (Rx) to report the output. Other uses async tasks. Feel free to make suggestions.

This is mostly useful when your application needs to invoke an external command-line utility to do some work and analyze its output.

Here are a few examples

Simple command with output capturing

  var outputTask = CmdHelper.RunCommand("c:\\Python27\\Python.exe","-file c:\\path\\to\\myprogram.py");
  Console.WriteLine("Python program started...");
  //Do some work here
  var output = await outputTask;
  Console.WriteLine("Output received");
  Console.WriteLine(output.Output);
  Console.WriteLine(output.Errors);

To log to file, similar to C:\> Command.exe >> c:\path\to\logfile.log

  var outputTask = await CmdHelper.RunCommand("c:\\Python27\\Python.exe","-file c:\\path\\to\\myprogram.py", "c:\\path\\to\\workingdir", "c:\\path\\to\\logfile.log");

Or if you are really in love with Reactive-Extensions like I am

  var console = CmdHelperRx.RunCommand("c:\\Python27\\Python.exe","-file c:\\path\\to\\myprogram.py", "c:\\path\\to\\workingdir");
  
   console
    .Where(data => data.Type.Equals(CommandLineDataType.Error))
    .Select(d => d.Data)
    .Subscribe(s => Debug.WriteLine("stderr line received: " + s));

About

Command Line Helper for .NET, Written in C#

License:GNU General Public License v2.0


Languages

Language:C# 100.0%