我想以编程方式从c#编译C代码.我正在尝试,但我还没有找到任何解决方案.这是我的代码.
try {
var info = new ProcessStartInfo {
FileName = "cmd.exe",
Arguments = "mingw32-gcc -o a Test.c"
};
var process = new Process { StartInfo = info };
bool start = process.Start();
process.WaitForExit();
if (start) {
Console.WriteLine("done");
}
} catch (Exception) {
Console.WriteLine("Not done");
}
Run Code Online (Sandbox Code Playgroud)
我使用Windows 7 VS2010和我已经安装的mingw32-gcc和我的的mingw32-gcc的环境变量是C:\ Program Files文件\代码块\ MinGW的\ BIN 任何帮助将不胜感激.提前致谢.
尝试
Process process = Process.Start(
@"C:\Program Files\CodeBlocks\MinGW\bin\mingw32-gcc.exe", "-o a Test.c");
Run Code Online (Sandbox Code Playgroud)
不需要调用cmd.exe程序。您可以直接带参数调用 mingw32-gcc.exe 程序。
编辑:
string szMgwGCCPath = "C:\\mingw32\\bin\\mingw32-gcc.exe"; // Example of location
string szArguments = " -c main.c -o main.exe"; // Example of arguments
ProcessStartInfo gccStartInfo = new ProcessStartInfo(szMgwGCCPath , szArguments );
gccStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(gccStartInfo );
Run Code Online (Sandbox Code Playgroud)
问候