C# How To Read Console Output With Parameters

前端 未结 1 841
野的像风
野的像风 2021-01-14 19:21

Is it possible to run a console application and get its outputted contents back as a string in C#?

I want to be able to use parameters when running the console app:<

相关标签:
1条回答
  • 2021-01-14 20:00

    This isn't the clearest thing I've read today, but I can only assume you're spawning a process (with Process.Start()?) and want to get it's output back into your program.

    If so, Process.StandardOutput is probably what you're looking for. For example:

    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();
    
    0 讨论(0)
提交回复
热议问题