请问如何才能接收到编译信息显示到窗口中的richTextBox中?你后面的代码不是已经实现了吗?
p.StartInfo.RedirectStandardOutput=true;
this.richTextBox3.AppendText(p.StandardOutput.ReadToEnd()+"\r\n");
使用p.StandardError.ReadToEnd()可以接收DOS命令的出错信息.
这两种调用方法的区别是什么?这个没有很深入的研究,应该是执行有错误的时候的输出吧,区别应该不大,都是标准输出的。

解决方案 »

  1.   

    谢谢先.
    调用C#编译器和DOS的方法不一样.
    前者是ProcessStartInfo类,后者是Process类,p.StandardError.ReadToEnd()是后者的方法.
    前者有没有类似的用法?
      

  2.   

    晕倒!你把后者的代码copy到前者上,就可以了。这些代码都放上:
    把p.ProcessStartInfo替换为startInfo即可:p.StartInfo.FileName="cmd.exe";
    p.StartInfo.CreateNoWindow=true;
    p.StartInfo.UseShellExecute=false;
    p.StartInfo.RedirectStandardInput=true;
    p.StartInfo.RedirectStandardOutput=true;
    p.StartInfo.RedirectStandardError=true;
    p.Start();
    p.StandardInput.WriteLine(str);
    p.StandardInput.WriteLine("exit");
      

  3.   

    谢谢juqiang,麻烦你详细一些.
    调用编译器执行的应该是csc.exe filepath(具体文件为参数)
    而调用DOS命令执行的应该是cmd.exe,然后是p.StandardInput.WriteLine(str);执行的是具体的命令
    两者应该不一样的啊
      

  4.   

    你是说这样的吗:这样不行,因为运行csc.exe时会提示找不到参数.
    public void Compile(string filepath)
    {
      System.Diagnostics.Process p=new Process();
      p.StartInfo.FileName="C:\\WINDOWS\\Microsoft.NET\\Framework\\v1.1.4322\\csc.exe ";
      p.StartInfo.CreateNoWindow=true;
      p.StartInfo.UseShellExecute=false;
      p.StartInfo.RedirectStandardInput=true;
      p.StartInfo.RedirectStandardOutput=true;
      p.StartInfo.RedirectStandardError=true;
      p.Start();
      p.StandardInput.WriteLine(filepath);
      p.StandardInput.WriteLine("exit");
      this.richTextBox3.AppendText(p.StandardOutput.ReadToEnd()+"\r\n");
    }
      

  5.   

    你的Arguments呢?没写上,当然不行了!还有,一般的,你最好指定WorkingFolder,否则如果这个app应用到其他的dll,可能会发生找不到的情况。