C#调用cmd编译C++的问题
Process p = new Process();//定义过程p.StartInfo.FileName = "cmd.exe";//设置命令名
p.StartInfo.Arguments = "/c " + commandText;//应用程序是穿的参数
p.StartInfo.UseShellExecute = false;//是否调用操作系统外部程序
p.StartInfo.RedirectStandardInput = true;//应用程序的输入是否从RedirectStandardInput读取
p.StartInfo.RedirectStandardOutput = true;//应用程序的输出是否写入RedirectStandardOutput
p.StartInfo.RedirectStandardError = true;//应用程序的错误是否写入RedirectStandardError
p.StartInfo.CreateNoWindow = false;//是否在新窗口启动该进程
string strOutput = null;
try
{
p.Start();
strOutput = p.StandardError.ReadToEnd();
p.WaitForExit();//等进程的推出
p.Close();
}
我用的是以上的代码去编译C++程序,在编译没有任何交互的代码时,例如直接打印hello world的代码毫无问题,但是如果cpp文件中涉及cin这些需要用户交互的一些操作,在p.start()之后cmd框就假死了,不知道怎么回事,但是我直接打开windows自带的cmd编译这些C++文件都没有出错都很顺利的生成了exe文件,很是不理解,求助大牛们 --------------------编程问答-------------------- 你试一下,那分开写main.cpp和其他子程序分开编写C++,这样交互式代码就不会出现逆说的问题 --------------------编程问答-------------------- 谢谢,但是我不是很懂您说的意思 --------------------编程问答-------------------- 需要向目标进程的标准输入写数据的话,参考http://msdn.microsoft.com/zh-cn/library/system.diagnostics.process.standardinput.aspx
补充:.NET技术 , ASP.NET