请问如何才能接收到编译信息显示到窗口中的richTextBox中?你后面的代码不是已经实现了吗?
p.StartInfo.RedirectStandardOutput=true;
this.richTextBox3.AppendText(p.StandardOutput.ReadToEnd()+"\r\n");
使用p.StandardError.ReadToEnd()可以接收DOS命令的出错信息.
这两种调用方法的区别是什么?这个没有很深入的研究,应该是执行有错误的时候的输出吧,区别应该不大,都是标准输出的。
p.StartInfo.RedirectStandardOutput=true;
this.richTextBox3.AppendText(p.StandardOutput.ReadToEnd()+"\r\n");
使用p.StandardError.ReadToEnd()可以接收DOS命令的出错信息.
这两种调用方法的区别是什么?这个没有很深入的研究,应该是执行有错误的时候的输出吧,区别应该不大,都是标准输出的。
调用C#编译器和DOS的方法不一样.
前者是ProcessStartInfo类,后者是Process类,p.StandardError.ReadToEnd()是后者的方法.
前者有没有类似的用法?
把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");
调用编译器执行的应该是csc.exe filepath(具体文件为参数)
而调用DOS命令执行的应该是cmd.exe,然后是p.StandardInput.WriteLine(str);执行的是具体的命令
两者应该不一样的啊
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");
}