Best Way to call external program in c# and parse output

后端 未结 1 824
终归单人心
终归单人心 2020-12-04 22:22

Duplicate

Redirect console output to textbox in separate program Capturing nslookup shell output with C#

I am looking to call an e

相关标签:
1条回答
  • 2020-12-04 22:58
    using System;
    using System.Diagnostics;
    
    public class RedirectingProcessOutput
    {
        public static void Main()
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/c dir *.cs";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
    
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
    
            Console.WriteLine("Output:");
            Console.WriteLine(output);    
        }
    }
    
    0 讨论(0)
提交回复
热议问题