2010-06-15 7 views
2

My C# 응용 프로그램에서 C++ 프로그램을 컴파일해야합니다. 거기에 버튼을 누르면 cl.exe를 열어야합니다. 누구든지 샘플 코드를 제공 할 수 있습니까? 일부 EXE 파일을 열려면C# 응용 프로그램의 cl.exe 열기

+1

:

또한, 당신이 읽고이 스레드에서 허용 대답을 이해하게? cl.exe를 실행하는 것은 다른 프로세스를 실행하는 것과 다르지 않습니다 ... –

+0

미안합니다. – Kasun

+0

http://www.csharpstation.com/howto/processstart.aspx –

답변

3
string filePath = "c:\program files\xyz\cl.exe"; 
System.Diagnostics.Process.Start(filePath); 
+0

안녕하세요,이 방법을 사용하면 다음 오류가 표시됩니다. 내가 어떻게 CL.EXE 의 파일 이름을 전달할 수 있습니다 System.ComponentModel.Win32Exception이었다 처리되지 않은 메시지 = 소스 "파일 지정을 찾을 수 없습니다"= "시스템" 있는 ErrorCode = -2147467259 NativeErrorCode = 2 스택 트레이스 : – Kasun

+0

CL.exe의 전체 경로 넣기 "c : \ program files \ xyz \ cl.exe" –

+0

이것은 올바른 대답이 아니므로 cl.exe는 % pATH %에 mspdb100.dll (및 다른 몇 가지 항목)이 있어야합니다. 나는 아래의 실제 해결책을 설명했다. –

1

사용할 수 : Process.Start("cl.exe");

+0

안녕하세요,이 방법을 사용하면 다음 오류가 표시됩니다. 어떻게 CL.exe에 대한 더미 이름을 전달할 수 있습니다 System.ComponentModel.Win32Exception이 처리되지 않았습니다 메시지 = "시스템이 지정된 파일을 찾을 수 없습니다"SourceCode = "System"ErrorCode = -2147467259 NativeErrorCode = 2 StackTrace – Kasun

+1

당신은 적절한 경로를 언급해야합니다. exe의. – anishMarokey

0

CL.EXE는 DLL 년대 % 경로 %에없는 그 필요합니다. 아키텍처에 맞는 올바른 배치 (x86 대 64 비트)를 실행해야합니다. 이렇게하면 cl.exe를 올바르게 시작할 수 있도록 환경이 업데이트됩니다.

  • C : \ 프로그램 파일 마이크로 소프트 비주얼 스튜디오 \ (86) 10.0 \ VC \ 빈 \

VCVARS32.BAT 나는 현재 명령을 실행

86은 (VS2010)가 여기 있습니다 콘솔에서 일괄 처리를 실행 한 다음 임시 파일에서 컴파일을 시작합니다.

string tempPath = Path.GetTempPath(); 
string tempName = "scrap_" + random.Next(); 

Process compiler = new Process(); 

compiler.StartInfo.FileName = "cmd.exe"; 
compiler.StartInfo.WorkingDirectory = tempPath; 
compiler.StartInfo.RedirectStandardInput = true; 
compiler.StartInfo.RedirectStandardOutput = true; 
compiler.StartInfo.UseShellExecute = false; 

compiler.Start(); 
compiler.StandardInput.WriteLine("\"" + @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat" + "\""); 
compiler.StandardInput.WriteLine(@"cl.exe /nologo /EHsc " + tempName + ".cpp"); 
compiler.StandardInput.WriteLine(@"exit"); 
string output = compiler.StandardOutput.ReadToEnd(); 
compiler.WaitForExit(); 
Debug.Write(output); 
compiler.Close(); 

현재 vcvars32.bat를 직접 실행하고 있습니다.하지만 C# 응용 프로그램의 환경을 올바르게 업데이트하는지 잘 모르겠습니다. 내가 작동하게되면 알려줄거야. 당신이 시도 무엇 ProcessStartInfo hanging on "WaitForExit"? Why?

관련 문제