System.Diagnostics.ProcessStartInfo

It is possible to redirect input/output using the ProcessStartInfo class.
You can use this class for better control over the process that is started.
In this example we are running a command prompt and getting a list of all the directories and then sending this information to a text file.


Create a New Project
Find Console App
untick "Use Top Level Statements"


System.Diagnostics.ProcessStartInfo start_info; 
start_info = ProcessStartInfo();
start_info.FileName = "cmd.exe";
start_info.Arguments = @"/C dir *";
start_info.CreateNoWindow = true;
start_info.RedirectStandardOutput = true;
start_info.UseShellExecute = false;

System.Diagnostics.Process? process_files;
process_files = Process.Start(start_info);

if (process_files != null)
{
   System.IO.StreamReader reader = process_files.StandardOutput;
   string results = reader.ReadToEnd();
   System.Console.WriteLine(results);
}


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext