Running Command Line tools in C#

In this post we will see, how to run a command line tool in c#

In the example I have taken Command prompt to fire a simple “dir” command.

public partial class CommandLine : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = "c:\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "/c dir";
si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
string output = si.StandardOutput.ReadToEnd();

this will print the output as follows


Tagged with: , , ,
  • Love your site man keep up the good work

  • Valuable info. Lucky me I found your site by accident, I bookmarked it.

  • Thank you, this post has been very worthile to read, I look forward to reading through more of this website.

  • great post!

  • really thanks i needed this

  • good post!

  • Many thanks for your personal anxiety as well as initiatives! These things in your web site is actually superb. In addition We dramatically understand your own suggestions. Personally they are vital matters. Nonetheless regards. Wonderful browse.

  • Just posting to tell you I love your blogs theme. I’ve been wondering, did you desgin it by yourself? if you did, can you reply with some tips on how you designed it? I am presently trying to create a personalized design and its pretty hard. Thanks 🙂

  • fantastic post, very informative. I wonder why the other specialists of this sector don’t notice this. You must continue your writing. I am sure, you have a huge readers’ base already!

  • Pingback: URL()