C # How to read console output with parameters

Is it possible to run a console application and return its output as a string in C #?

I want to be able to use options when starting a console application:

c:\files\app.exe -a 1 -b 2 -c 3
+2
source share
1 answer

This is not the clearest thing I read today, but I can only assume that you are creating a process (with Process.Start()?) And want to return it back to your program.

If so, Process.StandardOutputit is probably what you are looking for. For instance:

System.Diagnostics.ProcessStartInfo startInfo = 
    new System.Diagnostics.ProcessStartInfo(@"c:\files\app.exe",@"-a 1 -b 2 -c 3"); 
startInfo.UseShellExecute = false; 
startInfo.RedirectStandardOutput = true; 
Process p = Process.Start(startInfo);
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
+3
source

All Articles