To continue reading for free, register below or login
To read more you must become a member of SearchWinDevelopment.com
');
// -->

You have to use the System.Diagnostics.Process class. The following code issues a dir command and retrieves all the output generated by the command prompt in a string variable. You can write its contents to a file if you want:
ProcessStartInfo si = new ProcessStartInfo("cmd.exe");
// Redirect both streams so we can write/read them.
si.RedirectStandardInput = true;
si.RedirectStandardOutput = true;
si.UseShellExecute = false;
// Start the procses.
Process p = Process.Start(si);
// Issue the dir command.
p.StandardInput.WriteLine(@"dir c:");
// Exit the application.
p.StandardInput.WriteLine(@"exit");
// Read all the output generated from it.
string output = p.StandardOutput.ReadToEnd();
|