c pound

I reject your reality and substitute my own!

  Home  |   Contact  |   Syndication    |   Login
  46 Posts | 0 Stories | 23 Comments | 41 Trackbacks

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

Easy but with a couple little catches. If you need to do this, I recommend reading the help on the various properties of ProcessStartInfo. This code runs a console window that is visible to the user. There is a way to run commands by cmd.exe without actually showing a window... and I'm sure you can figure that out if you're interested enough. This should getcha started.

//set up to show a console window and send input to it
string pathToCmdExe = Environment.GetEnvironmentVariable("COMSPEC");
ProcessStartInfo psi = new ProcessStartInfo(pathToCmdExe);
psi.RedirectStandardInput = true;
psi.UseShellExecute =
false;

//open the console windown
Process console = Process.Start(psi);

//send it a command
console.StandardInput.WriteLine("dir");

//TODO: Send more commands, read the results, etc.

//close the console window
console.Close();

posted on Monday, February 27, 2006 7:09 AM