我需要从My C#应用程序编译C++程序。在我按下按钮时,我需要打开cl.exe。任何人都可以给我一些示例代码。从C#应用程序打开cl.exe
回答
string filePath = "c:\program files\xyz\cl.exe";
System.Diagnostics.Process.Start(filePath);
嗨,当我使用这种方法时,它将显示以下错误。如何传递桩名CL.EXE System.ComponentModel.Win32Exception了未处理 消息=“系统找不到指定文件” 源=“系统” 错误码= -2147467259 NativeErrorCode = 2 堆栈跟踪: – Kasun 2010-06-15 05:23:39
放入CL.exe的完整路径,例如“c:\ program files \ xyz \ cl.exe” – 2010-06-15 07:24:37
这不是正确的答案,cl.exe需要将mspdb100.dll(和其他一些项目)放在%PATH%中。我在下面概述了真正的解决方案。 – 2013-08-29 04:18:28
如果你想打开一些EXE可以使用:Process.Start("cl.exe");
嗨,当我使用这种方法时,它会显示以下错误。我怎样才能通过堆名称为CL.exe System.ComponentModel.Win32Exception是未处理消息=“系统找不到指定的文件”Source =“System”ErrorCode = -2147467259 NativeErrorCode = 2 StackTrace – Kasun 2010-06-15 05:23:59
您需要提及正确的路径的exe。 – anishMarokey 2010-06-15 06:31:44
cl.exe时需要DLL的不在%PATH%。您需要为架构执行正确的批处理(x86与64位)。这将更新您的环境,以便您可以正确启动cl.exe。
86就设在这里(VS2010):
- C:\ Program Files文件(x86)的\微软的Visual Studio 10.0 \ VC \ BIN \ VCVARS32.BAT
我目前启动命令控制台,执行批处理,然后在我的临时文件上启动编译。
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?
- 1. C# - 如何打开Excel应用程序?
- 2. C#UWP打开WPF应用程序
- 3. C#Winforms应用程序打开第二个Winforms应用程序
- 4. 从C++应用程序打开目标c窗口
- 5. 从通用Windows应用程序打开外部应用程序
- 6. 从网站打开UWP应用程序
- 7. 从应用程序打开Lync聊天
- 8. 从网页打开.NET应用程序
- 9. 从webapp打开本机应用程序
- 10. 从Java应用程序中打开Excel
- 11. 打开Twitter应用程序从意图
- 12. 从JavaFX打开外部应用程序
- 13. 检测从UILocalNotification应用程序打开
- 14. 从Gtalk打开桌面应用程序
- 15. 从WPF应用程序打开Outlook
- 16. 如何从EKEvent打开应用程序
- 17. 从android webview打开youtube应用程序
- 18. 从URL打开应用程序 - ios 10
- 19. 从iPhone应用程序打开iTunes
- 20. 从通知中打开应用程序
- 21. 从小部件打开应用程序
- 22. 从Python打开Excel应用程序
- 23. 从应用程序打开控制台
- 24. 从网页打开应用程序
- 25. 从我的应用程序打开iBooks
- 26. 从Android应用程序打开Gmail
- 27. 从iPhone打开PDF应用程序
- 28. 从Slider中打开Ionic2应用程序
- 29. 从后台打开android应用程序
- 30. GCM - 从通知打开应用程序?
?执行cl.exe与执行任何其他进程没有区别... – 2010-06-15 04:48:31
对不起,我无法得到它。 – Kasun 2010-06-15 04:51:00
http://www.csharp-station.com/howto/processstart.aspx – 2010-06-15 04:57:43