【发布时间】:2016-07-08 10:47:01
【问题描述】:
我正在开发一个简单的编译器,生成 IL 代码后的最后一个阶段是使用 ilasm 实用程序编译它,这就是崩溃发生的地方。
这里是该方法的完整代码(针对 Stack 稍作修改):
public static string ExecuteIL(string filename)
{
var ilasmp = new System.Diagnostics.Process ();
ilasmp.StartInfo.FileName = "ilasm";
ilasmp.StartInfo.Arguments = filename;
//Crash does not happen here:
ilasmp.Start ();
ilasmp.WaitForExit ();
var p = new System.Diagnostics.Process ();
p.StartInfo.FileName = "/usr/bin/time";
p.StartInfo.Arguments = "mono " + filename.Replace(".il", ".exe");
p.StartInfo.UseShellExecute = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
try{
//Crash happens HERE, but for some reason the exception does not get thrown
p.Start ();
}
catch{
throw new Exception ();
}
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit ();
return output;
}
只是说清楚:当我第一次调用Process.Start (ilasmp.Start ();) 时不会发生崩溃,但由于某种原因后来发生这种情况 (p.Start ();),
有趣的是不会抛出异常。
或者换句话说,代码只是崩溃了。
【问题讨论】:
-
你用的是什么版本的单声道?
-
@knocte,我认为它是最新版本之一,这是来自
mono --version的确切返回:Mono JIT compiler version 4.2.4 (tarball Fri Jun 10 10:12:47 UTC 2016) -
什么操作系统?你是怎么安装那个版本的单声道的?
-
@knocte OS 是 fedora,我使用 fedora 存储库管理器(现在是 dnf)安装它,换句话说:
dnf install mono
标签: c# linux mono process.start