windows MFC 用CreateProcess创建GCC进程!
发布网友
发布时间:2023-10-12 20:58
我来回答
共1个回答
热心网友
时间:2024-12-07 22:44
#include <windows.h>
#include <tchar.h>
int main()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
HANDLE hstderr;
TCHAR cmdLine[] = _T("gcc.exe -o123.exe -s 123.c");
ZeroMemory(&sa, sizeof sa);
sa.nLength = sizeof sa;
sa.bInheritHandle = TRUE;
hstderr = CreateFile(_T("gccout.txt"), GENERIC_WRITE, 0, &sa, CREATE_ALWAYS, 0, 0);
ZeroMemory(&si, sizeof si);
si.cb = sizeof si;
si.dwFlags = STARTF_USESTDHANDLES;
si.hStdOutput = INVALID_HANDLE_VALUE;
si.hStdError = hstderr;
si.hStdInput = INVALID_HANDLE_VALUE;
CreateProcess(0, cmdLine, 0, 0, TRUE, 0, 0, 0, &si, &pi);
CloseHandle(hstderr);
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
return 0;
}
代码已调试通过,还没加入出错判断,仅供参考
注:gcc在完全正常编译正常的情况下不会产生输出的,此时文件内容为空。
然后,gcc的环境你要配置好,path环境变量啊那些什么什么东西。mingw的话有一个mingwvars是专业给你干这种事用的