c pound

I reject your reality and substitute my own!
posts - 46, comments - 37, trackbacks - 40

My Links

News

Archives

Image Galleries

Blog Communities

Blog is a stupid word

Lunch Hour

Resources

Send a command to a console window (cmd.exe)

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();

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

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: