2016-07-08 7 views
0

간단한 컴파일러를 개발 중이며 IL 코드가 생성 된 후 마지막 단계는 충돌이 발생하는 ilasm 유틸리티로 컴파일합니다. 여기 Process.Start가 예외없이 중단됨

이 (약간 스택에 대한 수정) 방법의 전체 코드입니다 :

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; 
} 

그냥 명확하게하기 : 내가 처음 (ilasmp.Start();)에 대한 Process.Start를 호출 할 때 충돌이 발생하지 않고 웬일인지 나중에 (p.Start();), 그리고 흥미로운 점은 예외가 발생하지 않는다는 것입니다. 또는 다른 말로하면 코드가 단순히 충돌합니다. 당신이 마이크로 소프트에서

UseShellExecute = true; 

을 설정하는 거라면

+0

사용하는 모노의 버전? – knocte

+0

@knocte, 나는 그것이 최신 버전 중 하나라고 생각한다. 모노 버전의 정확한 반환은 다음과 같다 :'Mono JIT 컴파일러 버전 4.2.4 (tarball 6 월 10 일 10:12:47 UTC 2016)' –

+0

무엇 OS? 어떻게 그 모노 버전을 설치 했습니까? – knocte

답변

1

당신은 오류와 출력을 리디렉션 할 수 없습니다 : true로 RedirectStandardError을 설정하려면

당신은 거짓 인 UseShellExecute를 설정해야합니다. 그렇지 않으면 StandardError 스트림에서 읽기 예외가 발생합니다.

UseShellExecute Property

RedirectStandardError Property