By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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();
Dig Deeper on VB 6 to VB .NET Migration
Related Q&A from Daniel Cazzulino
Here Daniel Cazzulino explains how to load a DSL (domain specific language) domain model instance file programmatically. This requires the .NET type ... Continue Reading
Here we offer a glimpse at 12 of .NET development expert Danny Cazzulino's top ASP.NET questions and answers. Continue Reading
C# developers should NOT be modifying InitializeComponent method in the code-behind (or any of the variable definitions) by hand. Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.